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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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