DataGeek
DataGeek

Reputation: 3

Dynamically subtract two column values based on the filter selected and select a band on the basis of the value - Power BI DAX

We need to plot graph on Power BI where on X axis we have a band and on y axis we have count of customers that fall in this band We have a front end filter having values Type1 , type2, type3 (Note: This filter has multi select option enabled)

When any of the type is selected ,TotalValuebyCustomer(Column D) should be subtracted from the selected type column.

Here is our table:

enter image description here

When Type1 is selected For C01 ColumnD - Column E i.e; 15-5 =10 Band should be 6 to 10 . For C02 ColumnD - Column E i.e; 16-1 =15 Band should be 10+

Graph should show 1 customer in 6 to 10 band and 1 customer in 10+ band

When type2 is selected For C01 Column D- Column F i.e; 15-10=5 Band should be 1-5 For C02 Column D- Column F i.e; 16-12=4 Band should be 1-5
Graph should show count of 2 customers in 1-5 band

When type3 is selected For C01 Column D- Column G i.e; 15-13=2 Band should be 1-5 For C02 Column D- Column G i.e; 16-10=6 Band should be 6 to 10
Graph should show 1 customer in 1 to 5 band and 1 customer in 6 to 10 band

When Type 1 and Type2 both are selected For C01 Column D -[ColumnE + Column F] i.e; 15-(5+10)=0 Band should be 0 For C02 Column D- [ColumnE + Column F] i.e; 16-(1+12)=3 Band should be 1 to 5
Graph should show 1 customer in 0 band and 1 customer in 1 to 5 band

Expected Output:

Upvotes: 0

Views: 61

Answers (1)

Ryan
Ryan

Reputation: 2495

you can try this

  1. select type 1 ,2 and 3 and unpivot columns

enter image description here

then we will have a band table

enter image description here

at last, you need to create a measure

MEASURE =
VAR _list =
    DISTINCT ( 'Table'[Attribute] )
VAR _list2 =
    DISTINCT ( 'Table'[Category] )
VAR _tbl =
    ADDCOLUMNS (
        SUMMARIZE (
            FILTER ( 'Table', 'Table'[Attribute] IN _list && 'Table'[Category] IN _list2 ),
            'Table'[Customer],
            'Table'[Category],
            'Table'[Total ValuebyCustomer],
            "total", SUM ( 'Table'[Value] )
        ),
        "result", [Total ValuebyCustomer] - [total]
    )
RETURN
    COUNTROWS (
        FILTER (
            _tbl,
            [result] >= MAX ( Band[Left] )
                && [result] <= MAX ( Band[Right] )
        )
    )

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

Upvotes: 0

Related Questions