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

Measure Calculation based on Dynamic DAX Formulae stored as a part of table

Hi Everyone,

 

We are working on P/L and Financials reporting in power bi  and have lot of derived measures whose definitions are bound to change on frequnent basis based on User requirement. Hence planning to keep the dax formula dynamic.

 

We could manage dynamic row addtions using "SWITCH" and Variables. But when we try to retrieve the formulae stored in a table against every "Account Name", it returns literal string rather that evaluating the formula.

 

Any help is appreciated.

 

Scenario:

Account (Dimension):

Varshada_0-1617272274562.png

 

Elimination (Fact):

Varshada_1-1617272315786.png

Fact (Fact):

Varshada_2-1617272354656.png

 

Measure Table:

Value = SUM('Fact'[Amount]) + SUm(Elimination[Elimination])
Margin = CALCULATE(sum('Fact'[Amount]), FILTER(all('Account'),'Account'[Account Name]="Sales")) - CALCULATE(sum('Fact'[Amount]), FILTER(all('Account'),'Account'[Account Name]="Cost")) -CALCULATE(sum('Elimination'[Elimination]), FILTER(all('Account'),'Account'[Account Name]="Elimination"))
Amount Derived 1 =
Var A = IF(HASONEVALUE(Account[Account Name]),VALUES(Account[Account Name]),BLANK())
RETURN
SWITCH(A,"Margin",[Margin],[Value])
 
Results expected:
Varshada_3-1617272499692.png

Requirement : In the above table visual, we need the "Amount Derived 1" measure to dynamically calculate the value from the stored DAX expression or the [Table].[column] set up in Account Dimension.

 

Thanks,
Varshada
 

 

1 ACCEPTED SOLUTION
V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Unfortunately, formulas stored in tables cannot be switched, but measures can be changed dynamically based on the current row context.

See if it will help:

https://community.powerbi.com/t5/Community-Blog/Using-a-slicer-to-show-different-measures/ba-p/1724504 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

5 REPLIES 5
lbendlin
Super User
Super User

If you want to see progress you may want to vote for an existing idea or create a new one.

TWF2021
Regular Visitor

Hi,

 

This is the exact same problem I've been having with something i'm working on. I want to be able to dynamically pick up the DAX formulae from the tables in the load and haven't found a way of being able to pick up the string and execute it. Like you, i've just ended up seeing the string.

 

I was hoping there might be a way that one could change the definition of measures during the load phase, but it seems there isn't. If anyone finds a way it would be good to hear it!

V-lianl-msft
Community Support
Community Support

Hi @Anonymous ,

 

Unfortunately, formulas stored in tables cannot be switched, but measures can be changed dynamically based on the current row context.

See if it will help:

https://community.powerbi.com/t5/Community-Blog/Using-a-slicer-to-show-different-measures/ba-p/1724504 

 

Best Regards,
Liang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Anonymous
Not applicable

Thanks Liang, we have tried this alternative which makes us create those many measures and switch them on user input..was looking more from maintaining the DAX in table and picking it dynamically.

 

lbendlin
Super User
Super User

EVALUATE() is only available in external tools like DAX Studio.  You cannot do that in Power BI Desktop DAX (yet).

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.

Top Kudoed Authors