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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
rishari
Frequent Visitor

Make if statement optimized an total visible

I'm new to DAX. Kindly help me on this.
If i use zero for else statement, I'm getting error as insufficient memory.
I want to make the below dax faster and total to be visible. 

DAX =
IF (
      SUM ( Counter_flag ) = 1,
      CALCULATE ( DISTINCTCOUNTNOBLANK ( ColumnName ),
      KEEPFILTERS( 'table[Counter_flag]  = 1 )
)


5 REPLIES 5
Ahmedx
Super User
Super User

DAX =

VAR _t1 = SUM ( Counter_flag )
VAR _t2 = SUMX(DISTINCT( ColumnName ),1)
RETURN
IF (
      _t1 = 1,
      CALCULATE (_t2,
      KEEPFILTERS( 'table[Counter_flag]  = 1 )
)
Alex_Sawdo
Resolver I
Resolver I

You can probably re-write your DAX to not use the IF statement, by instead using a FILTER statement in your CALCULATE.

Like this:

CALCULATE(
DISTINTCOUNTNOBLANK([ColumnName]),
FILTER(
'table',
SUM('table'[Counter_flag]) = 1
)
)

This one is taking too long to load. (30 million rows are there)

you may try a combination of SUMX and CALCULATETABLE to acheive your goal and potentially improve performance.

 

SUMX (
CALCULATETABLE ( VALUES ( [Counter_flag] ), [Counter_flag] = 1 ),
SUM ( [Counter_flag] )
)

Hi @Keegan_Patton - Do you mean this ?

CALCULATE(
DISTINTCOUNTNOBLANK([ColumnName]),
SUMX (
CALCULATETABLE ( VALUES ( [Counter_flag] ), [Counter_flag] = 1 ),
SUM ( [Counter_flag] )
)
)

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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