March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
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.
Solved! Go to Solution.
@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
)
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:
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:
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.
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.
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:
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:
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.
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.
@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
)
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
16 | |
15 | |
7 | |
7 |
User | Count |
---|---|
37 | |
31 | |
16 | |
16 | |
12 |