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
Anonymous
Not applicable

Multiple IF statements in a measure

Hello Power Users,

I'm having some issues while creating a DAX measure. I want to create a measure with few conditions and calculate it. Below is my data look like. MY source is SSAS tabular model so can not create a calculated column in PBI.

 

Customer IDCustomer NameSalesQtyCostSHIP
1ABC10001030XY
2BCD20003050XY
3XYZ20002040CA
4ABDC10000399100CA

 

I have created some measures Sales YTD, QTY YTD, COST YTD's and i would like to create another measure by using QTY YTD. 

If SHIP="XY" then QTY YTD, IF SHIP="CA" then QTYYTD * COST YTD  other wise 0. 

 

I have create a measure like below.

Measure = SUMX(SWITCH(TRUE(), SHIP="XY", QTYYTD,
SHIP="CA", QTYYTD*COSTYTD,0)

This is giving me 0 or sometime memory exception issue.

 

How can i achieve this.

 

Thanks

5 REPLIES 5
Ainala
Frequent Visitor

@Jihwan_Kim , I tried helping with this solution but i'm not able to do it. Perhaps you can help. 

Anonymous
Not applicable

Hi  @Anonymous ,

It usually occurs when your computer doesn't have enough memory space for Power BI to run. Close other unnecessary running applications/softwares will spare more memory for Power BI if this error just appear occasionally. 

 

Also, if your table is in Import mode and you import a large amount of data into the model, it will consume much memory. You can use a small sample data when creating a report in Power BI Desktop. Then use query parameter to switch data source dynamically. After you complete the report and publish it to the service, you can change the query parameter to use the actual data source which has large data. See reference: Change the Source of Power BI Datasets Dynamically Using Power Query Parameters - RADACAD

 

Try to increase the Maximum allowed to 16000 under File / Options and Settings / Options / Global / Data Load.  Data Cache Management Options.

vyangliumsft_1-1654504854827.png

 

Refer to:

https://windowsreport.com/memory-error-allocation-failure/

 

Best Regards,

Liu Yang

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

amitchandak
Super User
Super User

@Anonymous , Try measure like

 

Measure = SUMX(table, SWITCH(TRUE(), [SHIP]="XY", [QTYYTD], [SHIP]="CA", [QTYYTD]*[COSTYTD],0) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

@amitchandak Thanks for the response. That is the measure i tried but i'm getting memory exception issue. 

Anonymous
Not applicable

@amitchandak @Anonymous I have changed the dataload to Import mode and loaded only 2 year of data and i'm not getting memory exception issues. the measure seems right but the condition is not right because only one condition is working otherone is not working.  When i select XY its working little bit right(some rows its not matching) and when i select CA it is giving me blank. Please help

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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