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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
kintela
Helper II
Helper II

Problems with SWITCH and IF in DAX

Hi

I'm trying to create a TotalHours measure in my Model that is connected to OCLG table in SAP Business One. In this table that store the activities exist the DurType Field which values are 'H', 'M'  or 'D'. 

 

In my SQL sentences, I use this: select sum (case when DurType='M' then Duration/60 else Duration end) from OCLG

 

And Now I want to translate this to DAX. But when I write this

 

TotalHoras = SWITCH(Horas[DurType],'M',Horas[Duration]/60,'H',Horas[Duration])

 

I have error: Cannot find table 'M'

 

But If I use IF I have error too

  

TotalHoras = IF([DurType]='M',[Duration]/60,[Duration])

 

Any idea, please?

 

regards

1 ACCEPTED SOLUTION

Hi

 

The probem in measures is that they need an aggregation to works:

 

This works to me now: 

 

TotalHoras = SUMX(Horas;if(Horas[Tipo]="M";Horas[Duration]/60;Horas[Duration]))

 

Thanks

View solution in original post

3 REPLIES 3
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @kintela,

 

Based on my understanding, you want to add a conditional column using DAX, right?

 

If so, I would suggest you create a calculated column rather than measure. To reslove the error, you should modify the DAX formula as below:

TotalHoras = SWITCH(Horas[DurType],"M",Horas[Duration]/60,"H",Horas[Duration])

Please pay attention to the double quote.

 

Thanks,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi

 

The probem in measures is that they need an aggregation to works:

 

This works to me now: 

 

TotalHoras = SUMX(Horas;if(Horas[Tipo]="M";Horas[Duration]/60;Horas[Duration]))

 

Thanks

Greg_Deckler
Community Champion
Community Champion

Try double quotes? "M"



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors