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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
MacarenaGB
Helper II
Helper II

Total is empty

I have some issues with my dax code because it doesn't sum the total, and after thinking it was because of a ISINSCOPE function, I get that the Switch I have inside doesn't sum either and I can't find how to fix it.

This is my code:

 

 

Total_Estimated_Resources =  
IF(
    ISINSCOPE('Dim_Project Database'[Program Name]) ,  
    SWITCH(
                SELECTEDVALUE('Dim_Project Database'[Program Name]),
                "Non billable" , NonBillingResourceCost,
                "Internal Project", PendingResources - NonBillingResourceCost,              
                 BLANK()
                ) 
    +
    IF(HASONEVALUE('Dim_Project Database'[Program Name]), Estimated_Resources,BLANK())     
    ,BLANK()
) 

 

 

 

 

Screenshot_15.png
 
What am I missing?? 🤔
Thanks!
1 ACCEPTED SOLUTION
MacarenaGB
Helper II
Helper II

I resolved the issues finally. 
First of all, I am not completely sure of what change fix the bug but, I created measures separated instead of using Variables in the same measure because I think it created some errors.

After, I separated a little the code proposed by @amitchandak  (thank you!) to  understand it better and here is the code: 

VAR T_ProgramName = SUMMARIZE('Dim_Project Database', 'Dim_Project Database'[Project Type], 'Dim_Project Database'[Program Name])

VAR T_SubTotal=
ADDCOLUMNS(T_ProgramName, "Col_Estimado", [Estimated_Resources], "Col_OtrosProyectos",SWITCH(
                [Program Name],
                "Non billable" , IF(PendingResources<=0, 0, IF( PendingResources >= NonBillingResourceCost, NonBillingResourceCost, PendingResources)),
                "Internal Project", IF(( PendingResources - NonBillingResourceCost) >0,PendingResources - NonBillingResourceCost,BLANK()),         
                BLANK()
                )
) 
VAR Total_Cost = SUMX(T_SubTotal, IF([Col_OtrosProyectos] = BLANK(), [Col_Estimado], [Col_OtrosProyectos]))

RETURN   Total_Cost

View solution in original post

11 REPLIES 11
MacarenaGB
Helper II
Helper II

I resolved the issues finally. 
First of all, I am not completely sure of what change fix the bug but, I created measures separated instead of using Variables in the same measure because I think it created some errors.

After, I separated a little the code proposed by @amitchandak  (thank you!) to  understand it better and here is the code: 

VAR T_ProgramName = SUMMARIZE('Dim_Project Database', 'Dim_Project Database'[Project Type], 'Dim_Project Database'[Program Name])

VAR T_SubTotal=
ADDCOLUMNS(T_ProgramName, "Col_Estimado", [Estimated_Resources], "Col_OtrosProyectos",SWITCH(
                [Program Name],
                "Non billable" , IF(PendingResources<=0, 0, IF( PendingResources >= NonBillingResourceCost, NonBillingResourceCost, PendingResources)),
                "Internal Project", IF(( PendingResources - NonBillingResourceCost) >0,PendingResources - NonBillingResourceCost,BLANK()),         
                BLANK()
                )
) 
VAR Total_Cost = SUMX(T_SubTotal, IF([Col_OtrosProyectos] = BLANK(), [Col_Estimado], [Col_OtrosProyectos]))

RETURN   Total_Cost

@MacarenaGB , Thanks for posting the solution. Kudos to you....

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here
MacarenaGB
Helper II
Helper II

I resolved the issues finally. 
First of all, I am not completely sure of what change fix the bug but, I created measures separated instead of using Variables in the same measure because I think it created some errors.

After, I separated a little the code proposed by @amitchandak  (thank you!) to  understand it better and here is the code: 



VAR T_ProgramName = SUMMARIZE('Dim_Project Database', 'Dim_Project Database'[Project Type], 'Dim_Project Database'[Program Name])

VAR T_SubTotal=
ADDCOLUMNS(T_ProgramName, "Col_Estimado", [Estimated_Resources], "Col_OtrosProyectos",SWITCH(
                [Program Name],
                "Non billable" , IF(PendingResources<=0, 0, IF( PendingResources >= NonBillingResourceCost, NonBillingResourceCost, PendingResources)),
                "Internal Project", IF(( PendingResources - NonBillingResourceCost) >0,PendingResources - NonBillingResourceCost,BLANK()),         
                BLANK()
                )
) 
VAR Total_Cost = SUMX(T_SubTotal, IF([Col_OtrosProyectos] = BLANK(), [Col_Estimado], [Col_OtrosProyectos]))

RETURN   Total_Cost

 

MacarenaGB
Helper II
Helper II

Hi! @amitchandak 
Something better but weird: 

MacarenaGB_0-1612975191724.png

It is muliplying by 10 the values.


Besides, I don't get what 
_1 and [_1] make.

Thanks for your great help!
 

 

@MacarenaGB , _1 is a new column in summarize. [_1], when used same in sumx .

As I can + sign near to program name. I think you need to add more columns to summarize add all columns on the row in that.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi! @amitchandak 

I'm trying to understand it, but not yet 😞

MacarenaGB_0-1613032322232.png

You are saying that, with the SUMX I will get the correct total and I need to create a virtual table with the proper columns to sum them correctly, right?
In my table, I have Year and Month, but even if remove them of the matrix, the result of the column don't change.

 

amitchandak
Super User
Super User

@MacarenaGB , Try like

 

Total_Estimated_Resources =  
Sumx(summarize('Dim_Project Database', 'Dim_Project Database'[Program Name],'Dim_Project Database'[Project Type], "_1", IF(
    ISINSCOPE('Dim_Project Database'[Program Name]) ,  
    SWITCH(
                SELECTEDVALUE('Dim_Project Database'[Program Name]),
                "Non billable" , NonBillingResourceCost,
                "Internal Project", PendingResources - NonBillingResourceCost,              
                 BLANK()
                ) 
    +
    IF(HASONEVALUE('Dim_Project Database'[Program Name]), Estimated_Resources,BLANK())     
    ,BLANK()
)),[_1]) 

 

refer: https://www.youtube.com/watch?v=ufHOOLdi_jk

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

@MacarenaGB , try like

 

Total_Estimated_Resources =  
Sumx(summarize('Dim_Project Database', 'Dim_Project Database'[Program Name],'Dim_Project Database'[Project Type],'Dim_Project Database'[Year],'Dim_Project Database'[Month], "_1", IF(
    ISINSCOPE('Dim_Project Database'[Program Name]) ,  
    SWITCH(
                SELECTEDVALUE('Dim_Project Database'[Program Name]),
                "Non billable" , NonBillingResourceCost,
                "Internal Project", PendingResources - NonBillingResourceCost,              
                 BLANK()
                ) 
    +
    IF(HASONEVALUE('Dim_Project Database'[Program Name]), Estimated_Resources,BLANK())     
    ,BLANK()
)),[_1]) 
Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi!

I tried that before but I can't access to the Calendar columns (it is other table)

MacarenaGB_1-1613038190450.png

 

@amitchandak any solution?

Thanks!

Hi, @MacarenaGB 

I think you can change the columns that you circled in the DAX formula to

'Dim_Project Database'[Year],'Dim_Project Database'[Month]

v-robertq-msft_0-1613547561628.png

 

 

If you still have a problem, you can post some sample data(without sensitive data) and your expected result.

How to Get Your Question Answered Quickly 

 

Best Regards,

Community Support Team _Robert Qin

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

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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