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

DAX calculation based on field constraint

I am trying to create a card visual which contains a dynamic calculation - in order to have the results filterable with slicers. 

 

Within the calculation however, there are certain contraints that needs to be applied and I am unsure how to write this in DAX. Based on the data screenshot below i basically need the calculation to do the following:

 

Result = Value (Case = Base & Scenario = 1. None) - Value (Case = Sale & Scenario = 2. Combined)

 

Then I need to use the result to calculate a % change:

 

% Change = Result /  Value (Case = Base & Scenario = 1. None)

 

Any advice on the DAX formula for this? I have tried to use Calculate combined with Filter, however not been able to get it to work.

 

Picture2.png

1 ACCEPTED SOLUTION

Hi @Anonymous,

Try the following changes:

Result =
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base";
Table[Scenario] = "1. None"
)
- CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Sale";
Table[Scenario] = "2. Combined"
)

The other measure
% Change = [Result] /
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base";
Table[Scenario] = "1. None"
)


Regards
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

4 REPLIES 4
MFelix
Super User
Super User

Hi ,

Not on my computer now but your measure should be something like this

Result =
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base"
&& Table[Scenario] = "1. None"
)
- CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Sale"
&& Table[Scenario] = "2. Combined"
)

The other measure
% Change = [Result] /
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base"
&& Table[Scenario] = "1. None"
)


Should work.

Regards
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix  Thanks - I have used the formula structure as suggested, but I get the following error message:

 

"The expressions contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression"

Hi @Anonymous,

Try the following changes:

Result =
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base";
Table[Scenario] = "1. None"
)
- CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Sale";
Table[Scenario] = "2. Combined"
)

The other measure
% Change = [Result] /
CALCULATE (
SUM ( Table[VALUE] );
Table[Case] = "Base";
Table[Scenario] = "1. None"
)


Regards
MFelix

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

@MFelix  Thank you very much - that seems to have done the trick!

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.