Forum Discussion
Wrong DAX
- 2 years ago
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 ) - Anonymous2 years ago
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.