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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Clint
Helper V
Helper V

Measures, Booleans and SuMX

Hello,

 

I am trying to write the following as a Measure vs creating another calculated column. The problem is not being able to use Sumx with a boolean expression.  Any ideas/thoughts on how to rewrite this as a Measure vs calculated column?

M_Init Var CF =

Switch(

TRUE(),

sumx('AssignmentTimephasedDataSet',AssignmentTimephasedDataSet[Assignment Work]<=sumx('Projects','Projects'[InitialEstimate])),1,

sumx('AssignmentTimephasedDataSet',AssignmentTimephasedDataSet[Assignment Work]<=sumx('Projects','Projects'[InitialEstimate]*1.2)),2,

sumx('AssignmentTimephasedDataSet',AssignmentTimephasedDataSet[Assignment Work]>sumx('Projects','Projects'[InitialEstimate]*1.2)),3

)

5 REPLIES 5
v-shex-msft
Community Support
Community Support

HI @Clint ,

I modify your formula and package them with if statement, you can try it if it works on your side:

M_Init Var CF =
VAR _sumPJ =
    CALCULATE ( SUM ( 'Projects'[InitialEstimate] ), 'Projects' )
VAR _sumPJ12 =
    CALCULATE ( SUM ( 'Projects'[InitialEstimate] ) * 1.2, 'Projects' )
RETURN
    SUMX (
        'AssignmentTimephasedDataSet',
        IF (
            [Assignment Work] <= _sumPJ,
            1,
            IF ( [Assignment Work] <= _sumPJ12, 2, IF ( [Assignment Work] > _sumPJ12, 3 ) )
        )
    )

If above not help, please share some sample data with expected result to help us clarify your scenario.
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Hello @v-shex-msft 

I used the following DAX (based on your example) and got some odd results (see embedded image)

M_Init Est Variance CF =

Var Green =

sumx('Projects',[InitialEstimate])

VAR Amber =

sumx('Projects',[InitialEstimate]*1.2)

Return

sumx('AssignmentTimephasedDataSet',

If('AssignmentTimephasedDataSet'[Assignment Work]<=Green,1,

if('AssignmentTimephasedDataSet'[Assignment Work]<=Amber,2,3)

))

 

IF results.PNG

Hi @Clint ,

Maybe you can create a variable summary table to store 'Assignment Timephased DataSet' records and a custom column with the replaced result based on condition, then you can use iteration function on this table to get total result:

Measure Totals, The Final Word  
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Nathaniel_C
Super User
Super User

Hi @Clint ,

How about with variables. Put your Switch after return and your variables before return. And maybe just use SUM()

M_Init Var CF =
var _first = sumx('AssignmentTimephasedDataSet',AssignmentTimephasedDataSet[Assignment Work]
var _sec = sumx('Projects','Projects'[InitialEstimate])

//then your first one in switch is _first <= _sec, 1
return

Switch(

TRUE(),

_first <= _sec, 1,
next,2
next,3

 

)


Let me know if you have any questions.

If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos 👍are nice too.
Nathaniel





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

Proud to be a Super User!




Hi @Nathaniel_C ,

 

Thank you for the quick feedback. When I (tried) to follow your example using the following DAX;

M_Init Est Variance CF =

Var AssignWork =
sumx('AssignmentTimephasedDataSet',[Assignment Work])
Var Green =
sumx('Projects',[InitialEstimate])
VAR Amber =
sumx('Projects',[InitialEstimate]*1.2)
Return

Switch(TRUE(),
AssignWork<=Green,1,
AssignWork<=Amber,2,
AssignWork>Amber,3
)
It returned a 1,2 or 3 but it created multiple rows for each entry.
Switch results.PNG

 

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

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

July Newsletter

Fabric Community Update - July 2024

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