Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Card value depending which column is filtered

Hi everyone,

I have 2 different columns which are filters: Month and Quarter.

 

I also have a card which I need calculation depending which filter is applied. For example:

 

I have 2 numeric columns (Amount1 and Amount2)

If I do a month filter, so take the value Amount1 and substract Amount2 of the month.

If I do a quarter filter, I take the value of SUM(Amount1) and need substract the last value of the Quarter for Amount 2.

 

Month     -     Quarter     -     Amount1     -     Amount2

01                   1                      100                     100

02                   1                      153                     800

03                   1                      123                     400

04                   2                      543                     600

05                   2                      234                     300

06                   2                      123                     200

If I filter Month 05, so 234 - 300

If I filter Q2, so 543+234+123 - 200

 

If I filter Month 01, so 100 - 100

If I filter Q1, so 100+153+123 - 400

 

I guess is a IF but depending which table/column is filtered and active, but I cannot find nothing.

 

Thanks!!

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

    Expected result measure: =
    SWITCH (
        TRUE (),
        HASONEFILTER ( Data[Month] ), SUM ( Data[AmountOne] ) - SUM ( Data[AmountTwo] ),
        HASONEFILTER ( Data[Quarter] ),
            SUM ( Data[AmountOne] )
                - CALCULATE (
                    SUM ( Data[AmountTwo] ),
                    FILTER ( VALUES ( Data[Month] ), Data[Month] = MAX ( Data[Month] ) )
                )
    )
    

     

1 Reply

  • Hi,

    Please check the below picture and the attached pbix file.

     

     

    Expected result measure: =
    SWITCH (
        TRUE (),
        HASONEFILTER ( Data[Month] ), SUM ( Data[AmountOne] ) - SUM ( Data[AmountTwo] ),
        HASONEFILTER ( Data[Quarter] ),
            SUM ( Data[AmountOne] )
                - CALCULATE (
                    SUM ( Data[AmountTwo] ),
                    FILTER ( VALUES ( Data[Month] ), Data[Month] = MAX ( Data[Month] ) )
                )
    )