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
sivarajan21
Helper V
Helper V

Find Dax measures instead of calculated tables that returns similar result to improve efficiency

Hi,

 

I have this below dataset which has calculated columns(Profile,Direct,Target,Accrual kwh,Accrual Source)

PoinTS_idData dateMonthProfileDirectTargetAccrual kwhAccrual Source
12301/04/2022 00:00Apr  4444Target
12302/04/2022 00:00Apr3 443Profile
12303/04/2022 00:00Apr  4444Target
12304/04/2022 00:00Apr  4444Target
12305/04/2022 00:00Apr  4444Target
12306/04/2022 00:00Apr  4444Target
12307/04/2022 00:00Apr  4444Target
12308/04/2022 00:00Apr50 4450Profile
12309/04/2022 00:00Apr65 4465Profile
12310/04/2022 00:00Apr0 440Profile
12311/04/2022 00:00Apr87 4487Profile
12612/04/2022 00:00Apr 633.333333336Direct
12613/04/2022 00:00Apr  33.3333333333.33333333Target
12614/04/2022 00:00Apr  33.3333333333.33333333Target
12615/04/2022 00:00Apr 833.333333338Direct

 

Please find attached sample dataset in below link:

Missing Calendar.pbix

 

I am happy that I was able to create this calculated table. But is there any way we can achieve the same result(table) using Dax measures instead of calculated columns. for example, I mean to ask that I have calculated column measure for profile as below:

Profile = CALCULATE (
        SUMX('Table','Table'[Units]),
        FILTER (
          'Table',
            'Table'[Points Id] = 'Missing Calendar date_1'[PoinTS_id]
            && 'Table'[Data Date] = 'Missing Calendar date_1'[Data date]
            && 'Table'[Source] = "Profile"))

 

Is it possible to write the same above measure as a Dax measure that gives the same result as the profile column gives now as below?

PoinTS_idData dateMonthProfile
12301/04/2022 00:00Apr 
12302/04/2022 00:00Apr3
12303/04/2022 00:00Apr 
12304/04/2022 00:00Apr 
12305/04/2022 00:00Apr 
12306/04/2022 00:00Apr 
12307/04/2022 00:00Apr 
12308/04/2022 00:00Apr50
12309/04/2022 00:00Apr65
12310/04/2022 00:00Apr0
12311/04/2022 00:00Apr87
12612/04/2022 00:00Apr 
12613/04/2022 00:00Apr 
12614/04/2022 00:00Apr 
12615/04/2022 00:00Apr 

 

Reason I wanted dax measures is to increase efficiency. At present,when i use this calculated table for my large dataset, it gives me 

errors such as 'There's not enough memory to complete this operation. Please try again later when there may be more memory available'

 

Please let me know if you need further info.

 

Thanks in advance

@Ahmedx @AlB @lbendlin @grantsamborn @amitchandak @Greg_Deckler 

6 ACCEPTED SOLUTIONS
lbendlin
Super User
Super User

see if the attached version is any faster.

View solution in original post

pls try this

Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))&""
----
or
Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))+0

 

View solution in original post

pls try this

Accrual sai kwh = 
       IF([Profile22_all]="",[TargetSai_all],[Profile22_all])

Screen Capture #1121.png

View solution in original post

pls try this

Accrual sai kwh = 
       IF([Profile22_all]="",
       IF([Direct sai_all],[Direct sai_all],[TargetSai_all]),[Profile22_all])

View solution in original post

Ahmedx
Super User
Super User

hi! you can try this

Screen Capture #1130.png

View solution in original post

17 REPLIES 17
Ahmedx
Super User
Super User

hi! you can try this

Screen Capture #1130.png

Hi @Ahmedx ,

 

Many thanks for all this solutions and your patience sir

This solutions works like a gem on large dataset.

I will close this long query and and accept this as a solution.😊

 

Thank you both and community once again

Hi @Ahmedx ,

 

Thanks for your quick response sir😊

I am amazed with your skills and its a super solution.

 

Will use this solution on my large dataset and get back to you with feedback

 

Thanks in advance

lbendlin
Super User
Super User

see if the attached version is any faster.

Hi @lbendlin ,

 

This worked like a charm and you are amazing 😊

 

The problem of memory issues were eliminated. Just to confirm, you made changes to profile & direct calculated column by adding variables correct?

If so, Wow! spot on! you made my day.  you made it look so easy and many thanks

 

Before closing this query,If you could help me with the below, that means a lot to me.

I want a measure to return rows (Data date & PoinTS_id) that has blank data(no profile) along with rows that has data. for example in below dataset , Profile was created using calculated column.

PoinTS_idData dateMonthProfile
12301/04/2022 00:00Apr 
12302/04/2022 00:00Apr3
12303/04/2022 00:00Apr 
12304/04/2022 00:00Apr 
12305/04/2022 00:00Apr 
12306/04/2022 00:00Apr 
12307/04/2022 00:00Apr 
12308/04/2022 00:00Apr50
12309/04/2022 00:00Apr65
12310/04/2022 00:00Apr0
12311/04/2022 00:00Apr87
12612/04/2022 00:00Apr 
12613/04/2022 00:00Apr 
12614/04/2022 00:00Apr 
12615/04/2022 00:00Apr 

But is it possible to create a measure to achieve? @Ahmedx gave me this beautiful measure 

Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))

But this returns only rows with profile data(as shown in below screenshot) and not all the dates and points for which profile has blank rows.

sivarajan21_1-1684375016305.png

 

The expected output is:

sivarajan21_0-1684374321544.png

Expected Dax measure will return both rows hightlighed in 2 colors.

 

Please let me know if you need further info

Thanks in advance!

 

Dax measure will return rows hightlighed in 2 colors.

Ahmedx
Super User
Super User

pls try this

Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))

Hi @Ahmedx ,

 

Thanks for your quick response!

This really amazing dax! we are really very close. I tried to use this dax to check and here is my observation:

It returns me all the rows where there are data's: for example as shown in below screenshot

sivarajan21_0-1684370441519.png

Upto this point measure works great. The measure would return dates that has data & no data.I wanted to return rows (date & point id) that has blank data(no profile) along with rows that has data.

The expected output is:

sivarajan21_1-1684370671286.png

Dax measure will return rows hightlighed in 2 colors.

 

Please let me know if you need further info

Thanks in advance

pls try this

Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))&""
----
or
Profile22 = 
VAR _t1 = MAX('Missing Calendar date_1'[PoinTS_id])
VAR _t2 =MAX('Missing Calendar date_1'[Data date])

RETURN
CALCULATE (
                MAX('Table'[Units]),
        FILTER (ALL(
          'Table'),
            'Table'[Points Id] = _t1
            && 'Table'[Data Date] = _t2
            && 'Table'[Source] = "Profile"))+0

 

Hi @Ahmedx ,

 

Thanks for your patience!

Just finished the testing, above dax works really well. Brilliant stuff! 

One last bit requires your help before this query is closed. Below measure is not returning the correct values:

Accrual sai kwh =
COALESCE ( [Profile22_all], [Direct sai_all], [TargetSai_all] )

We want this measure to look through [Profile22_all] column and if there is any value then retrun it.

If [Profile22_all] is blank then look for [Direct sai_all] to return any value if present.

If [Direct sai_all] is blank then look for  [TargetSai_all] to return any value if present.

 

But in our case, it returns value from  [Profile22_all] only and does not look through [Direct sai_all], [TargetSai_all]  columns. for example look at the below screenshot:

sivarajan21_2-1684387806225.png

 

Red colour column(Accrual sai kwh) is the measure we created and this returns profile column values perfectly.

we expect black colour marked rows would return target values in Accrual sai kwh 

similarly green colour marked rows would return Direct values in Accrual sai kwh.

 

The expected output would be:

sivarajan21_3-1684387868117.png

 

Please let me know if you need further info

Thanks in advance

 

I think this is because of the so-called auto exist
You need to create a calendar table and from there pull the date into the matrix

Share sample pbix file to help you.

Hi @Ahmedx ,

 

Many thanks for your quick response

Interesting to know the term 'auto exist'.

 

Apologise for not sharing the pbix file

PFA file in below link

Missing Calendar.pbix

 

Please can you guide me through this sir?

 

Please let me know if you need further info

Thanks in advance

pls try this

Accrual sai kwh = 
       IF([Profile22_all]="",[TargetSai_all],[Profile22_all])

Screen Capture #1121.png

Hi @Ahmedx ,

 

Thanks for your quick response sir

Thats a brillaint solution, but need a slight modification to include 

'Direct sai_all' also in the result. for example in below screenshot
sivarajan21_0-1684392358703.png

Above pic shows, for 4/12/2022 we have 6 in 'Direct sai_all' column which is needs to be included in 'Accrual sai kwh_Ahmedx' column. Only when 'Direct sai_all' is blank we need the '

TargetSai_all' values to be included.
Similarly pic shows, for 4/15/2022 we have 8 in 'Direct sai_all' column which is needs to be included in 'Accrual sai kwh_Ahmedx' column. 
 
Priority goes like this: If 'Profile22_all' is not blank return value, if blank check 'Direct sai_all' is blank or not. if not blank return value else return 'TargetSai_all'(this will not be blank)
Just to confirm, Is it possible to use COALESCE function to achieve above?
'
So expected output will be as follows:
sivarajan21_1-1684392724496.png

 

'Shared the updated file in below link:

Missing Calendar.pbix

 

Please let me know if you need further info

Thanks in advance

pls try this

Accrual sai kwh = 
       IF([Profile22_all]="",
       IF([Direct sai_all],[Direct sai_all],[TargetSai_all]),[Profile22_all])

Hi @Ahmedx ,

 

Apologise for delay as I was in testing phase from yesterday.

Thanks for a wonderful solution! and it works like a gem😊. you made my day!

I am going to accept this as solution but before that I expect the total column of this measure to show as 549.67(sumx of all rows of 'Accrual sai kwh_ahmedx_2'.

 

But currently it shows as below:

sivarajan21_0-1684472727974.png

 

Expected total will be:

sivarajan21_1-1684472821656.png

 

Please find file is in below link:

Missing Calendar.pbix

 

Please let me know if you need further info

Thanks in advance

Hi @Ahmedx ,

 

Apologise,Just saw your message

Many thanks for your quick response  and this works like a charm😊

Wow! spot on! you made my day.  you made it look so easy and many thanks 

You are so fluent with the measures that you made it look so easy. I don't have any words to describe. 

 

Let me have a look into this measure to test for my large dataset.

Once this is done, I will close this query.

 

Many thanks guys! seriously brilliant stuff from you both 

@Ahmedx and @lbendlin  god bless you both

 

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.