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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Stymied9
Frequent Visitor

DAX function to M language?

I have the following DAX function which works in Power BI.  

 

New Formula Output = IF('Global DSR MTMS'[TOTAL WEIGHT]>(19958 * 0.85), "Optimized", SWITCH('Global DSR MTMS'[EQUIPMENT TYPE], "20FT_COFC", IF('Global DSR MTMS'[CBM]>(33 * 0.85), "Optimized", "Not Optimized"), "40FT_COFC", IF('Global DSR MTMS'[CBM]>(67 * 0.85), "Optimized", "Not Optimized"), "40FT_HC", IF('Global DSR MTMS'[CBM]> (76 * 0.85), "Optimized", "Not Optimized"), "Not Optimized" ) )

 

Unfortunately, I need to do some groupings with this and other columns.  The problem I have is all of my columns were built outside of the query editor, so I do not have access to them in the grouping option.  So I had to rebuild them all in the query editor which is M language...and this is the last funtion for me to complete, and I cannot seem to make it work. 

Any help would be greatly appreciated.

 

Thanks !

3 REPLIES 3
Eric_Zhang
Employee
Employee


@Stymied9 wrote:

I have the following DAX function which works in Power BI.  

 

New Formula Output = IF('Global DSR MTMS'[TOTAL WEIGHT]>(19958 * 0.85), "Optimized", SWITCH('Global DSR MTMS'[EQUIPMENT TYPE], "20FT_COFC", IF('Global DSR MTMS'[CBM]>(33 * 0.85), "Optimized", "Not Optimized"), "40FT_COFC", IF('Global DSR MTMS'[CBM]>(67 * 0.85), "Optimized", "Not Optimized"), "40FT_HC", IF('Global DSR MTMS'[CBM]> (76 * 0.85), "Optimized", "Not Optimized"), "Not Optimized" ) )

 

Unfortunately, I need to do some groupings with this and other columns.  The problem I have is all of my columns were built outside of the query editor, so I do not have access to them in the grouping option.  So I had to rebuild them all in the query editor which is M language...and this is the last funtion for me to complete, and I cannot seem to make it work. 

Any help would be greatly appreciated.

 

Thanks !


@Stymied9

Could you post any sample data and expected output so that we can offer further suggestion?

Eric,

A colleague of mine and I have been working on this.  We have come up with a formula that is forcing no errors in the Query Editor section, however, it is not working properly.  It seems to not not be following the search requirements properly.  Instead of looking for the proper Equipment Type, and if found, going through the next steps and providing the proper response, it is providing a response for all rows. 

 

Here is the formula we have come up with.

if [TOTAL WEIGHT] > (19958 * 0.85) then "Optimized" else if [EQUIPMENT TYPE] = "20FT_COFC" and [CBM] > (33 * 0.85) then "Optimized" else if [EQUIPMENT TYPE] = "40FT_COFC" and [CBM] > (67 * 0.85) then "Optimized" else if [EQUIPMENT TYPE] = "40FT_HC" and [CBM] > (76 * 0.85) then "Optimized" else "Not Optimized")

And here is some sample data:

Before.PNG

 

 

Please see the below graph.  For all those items highlighted in green...those are items that should make the formula provide an "Optimized" response.  If there is no green in the row, it should provide an "Not Optimized" response.  AND...if the Equipment Type does not match at all (20FT_COFC, 40FT_COFC, or 40FT_HC) the response should be a blank or null, but preferably a blank.

 

After.PNG

 

I hope that makes sense. 

 

Thanks !

Greg_Deckler
Super User
Super User

Take a look at this for help in replicating your SWITCH statement in Power Query. I assume that's where the stumbling block is:

 

https://www.powerquery.training/portfolio/replicate-power-pivots-switch-function/

 

 


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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