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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
toum
Helper II
Helper II

Wrong DAX

Please, I need your help. This DAX formula does not work. Could you please tell me what I am doing wrong?

I got True/false error. But when I get rid of the variable AmountCateg and I do the calculation of the Switch inside the big measure it works fine, but I want to use the AmountCateg as a variable because I will do another switch for the end result.

 

VAR SelectedColumn = SELECTEDVALUE('Categories'[ID])
VAR AmountCateg =
SWITCH(
SelectedColumn,
"A", Production[AmountB],
"B", Production[AmountB],
"C", Production[AmountC],
0 -- Default value in case SelectedColumn is not "A", "B", or "C"
)

RETURN
CALCULATE(
COUNTROWS(Production),
AmountCateg >= 1000
)

 

 

Thank you. 

2 ACCEPTED SOLUTIONS
Greg_Deckler
Community Champion
Community Champion

@toum Maybe:

VAR SelectedColumn = SELECTEDVALUE('Categories'[ID])
VAR AmountCateg =
SWITCH(
SelectedColumn,
"A", Production[AmountB],
"B", Production[AmountB],
"C", Production[AmountC],
0 -- Default value in case SelectedColumn is not "A", "B", or "C"
)

RETURN
CALCULATE(
COUNTROWS(Production),
[AmountCateg] >= 1000
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

Anonymous
Not applicable

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:

HI,@toum 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718600437518.png

vlinyulumsft_1-1718600453261.png

2.I then created the following two measure:

AmountB = CALCULATE(SUM('Production'[VALUES]),'Production'[ID]="B")
AmountC = CALCULATE(SUM('Production'[VALUES]),'Production'[ID]="C")

3.Then I will you provide the code as a measure value, he also reported an error:

vlinyulumsft_2-1718600531456.png

The main reason for this error is that the filter criteria you provide are not clear.

4.Here's assuming your need is to determine if the current metric is greater than 1000, and then count the number of rows with the same id as the slicer:

Measure = 
VAR SelectedColumn = SELECTEDVALUE('Categories'[ID])
VAR AmountCateg =
SWITCH(
SelectedColumn,
"A", Production[AmountB],
"B", Production[AmountB],
"C", Production[AmountC],
0 -- Default value in case SelectedColumn is not "A", "B", or "C"
)

RETURN
IF(AmountCateg>1000,CALCULATE(COUNTROWS('Production'),'Production'[ID]=SelectedColumn),0)

5.Here's my final result, which I hope meets your requirements.

vlinyulumsft_3-1718600569186.png

vlinyulumsft_4-1718600577334.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.


Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

2 REPLIES 2
Anonymous
Not applicable

Thanks for the reply from @Greg_Deckler , please allow me to provide another insight:

HI,@toum 

Regarding the issue you raised, my solution is as follows:

1.First I have created the following table and the column names and data are the data you have given:

vlinyulumsft_0-1718600437518.png

vlinyulumsft_1-1718600453261.png

2.I then created the following two measure:

AmountB = CALCULATE(SUM('Production'[VALUES]),'Production'[ID]="B")
AmountC = CALCULATE(SUM('Production'[VALUES]),'Production'[ID]="C")

3.Then I will you provide the code as a measure value, he also reported an error:

vlinyulumsft_2-1718600531456.png

The main reason for this error is that the filter criteria you provide are not clear.

4.Here's assuming your need is to determine if the current metric is greater than 1000, and then count the number of rows with the same id as the slicer:

Measure = 
VAR SelectedColumn = SELECTEDVALUE('Categories'[ID])
VAR AmountCateg =
SWITCH(
SelectedColumn,
"A", Production[AmountB],
"B", Production[AmountB],
"C", Production[AmountC],
0 -- Default value in case SelectedColumn is not "A", "B", or "C"
)

RETURN
IF(AmountCateg>1000,CALCULATE(COUNTROWS('Production'),'Production'[ID]=SelectedColumn),0)

5.Here's my final result, which I hope meets your requirements.

vlinyulumsft_3-1718600569186.png

vlinyulumsft_4-1718600577334.png

Can you share sample data and sample output in tabular format if I am misunderstanding? Or a sample pbix after removing sensitive data. We can better understand the problem and help you.


Please find the attached pbix relevant to the case.

 

Best Regards,

Leroy Lu

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

 

 

 

 

Greg_Deckler
Community Champion
Community Champion

@toum Maybe:

VAR SelectedColumn = SELECTEDVALUE('Categories'[ID])
VAR AmountCateg =
SWITCH(
SelectedColumn,
"A", Production[AmountB],
"B", Production[AmountB],
"C", Production[AmountC],
0 -- Default value in case SelectedColumn is not "A", "B", or "C"
)

RETURN
CALCULATE(
COUNTROWS(Production),
[AmountCateg] >= 1000
)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.