Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Return value which has been filtered in DAX

Hi all,

 

I am trying to find a way to manually set target goals for my KPI visual based on a filtered value (base currency). The goals for each currency are as follows:

ActiveDocs with CurrencyCode Table.PNG

 

I can get the goals to work for one given currency (say GBP), by using the code

 

ActDocsRedTarg = IF(HASONEVALUE(KPI2[ActiveDocsRed]), VALUES(KPI2[ActiveDocsRed]), CALCULATE(MINA(KPI2[ActiveDocsRed]), KPI2[CurrencyCode] = "GBP"))

 

 

and it appears as it should

KPI with GBP filter.PNG

 

But this isn't very useful when the currency code is say USD where the goals should be 1250 and 2500 as I have had to hardcode GBP into the DAX.

KPI with USD filter.PNG

 

Is there a way I can write the last bit of code to say something like:

... KPI2[CurrencyCode] = (Value which has been filtered)

 

Thanks in advance!

1 ACCEPTED SOLUTION

@Anonymous 

 

Try adding a FILTER in your formula.

 

ActDocsRedTarg = 
IF(
    HASONEVALUE(KPI2[ActiveDocsRed]), 
    VALUES(KPI2[ActiveDocsRed]), 
    CALCULATE(
        MINA(KPI2[ActiveDocsRed]), FILTER(KPI2,
        KPI2[CurrencyCode] = SELECTEDVALUE(GeneralLedgerStructure[BaseCurrency])
    )
)



Lima - Peru

View solution in original post

4 REPLIES 4
Vvelarde
Community Champion
Community Champion

@Anonymous 

 

hi, try with SELECTEDVALUE.

 

Regards

 

Victor




Lima - Peru
Anonymous
Not applicable

 

I have rearranged the code for ease. And GeneralLedgerStructure[BaseCurrency] is the field being filtered and only contains currency values from the previous post.

 

I tried with SELECTEDVALUE but it just returned the error:

"A function 'SELECTEDVALUE' has been used in a True/False expression that is used as a table filter expression. This is not allowed."

 

This is my code

ActDocsRedTarg = 
IF(
    HASONEVALUE(KPI2[ActiveDocsRed]), 
    VALUES(KPI2[ActiveDocsRed]), 
    CALCULATE(
        MINA(KPI2[ActiveDocsRed]), 
        KPI2[CurrencyCode] = SELECTEDVALUE(GeneralLedgerStructure[BaseCurrency])
    )
)

 

 

 

@Anonymous 

 

Try adding a FILTER in your formula.

 

ActDocsRedTarg = 
IF(
    HASONEVALUE(KPI2[ActiveDocsRed]), 
    VALUES(KPI2[ActiveDocsRed]), 
    CALCULATE(
        MINA(KPI2[ActiveDocsRed]), FILTER(KPI2,
        KPI2[CurrencyCode] = SELECTEDVALUE(GeneralLedgerStructure[BaseCurrency])
    )
)



Lima - Peru
Anonymous
Not applicable

It works!

 

Thank you!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.