cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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

Accepted Solutions
Highlighted
Community Champion
Community Champion

Re: Return value which has been filtered in DAX

@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
Highlighted
Community Champion
Community Champion

Re: Return value which has been filtered in DAX

@Anonymous 

 

hi, try with SELECTEDVALUE.

 

Regards

 

Victor




Lima - Peru
Highlighted
Anonymous
Not applicable

Re: Return value which has been filtered in DAX

 

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])
    )
)

 

 

 

Highlighted
Community Champion
Community Champion

Re: Return value which has been filtered in DAX

@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

Highlighted
Anonymous
Not applicable

Re: Return value which has been filtered in DAX

It works!

 

Thank you!

Helpful resources

Announcements
Community Blog

Community Blog

Visit our Community Blog for articles, guides, and information created by fellow community members.

Using the Community

Using the Community

Need help with the Power BI Community? Our 'Using the Community' support articles are a great place to start.

Community Summit North America

Community Summit North America

Innovate, Collaborate, Grow. The top training and networking event across the globe for Microsoft Business Applications

Power Platform 2020 release wave 2 plan

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors