cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Kroth
Microsoft
Microsoft

DAX Calculated Table

I am trying to store a Calculated Table as a variable to pass later on as a parameter in Calculate() so that a measure is only evaluated for the values in the calculated table.

 

1. Am I typing something wrong in the DAX to accomplish a Calculated Table with only the unique combinations of Dim1 and Dim2?

 

2. Does passing a calculated table in a Calculate() parameter filter as I am expecting?

 

This code does not seem to be doing that, even though I thought it would (The measure does not seem to be filtered).

 

Thank you for any assistance and if you need more information let me know!

 

Measure1:=

VAR Filter1 =
CALCULATETABLE (
    ADDCOLUMNS (
        VALUES ( 'Table1'[Dim1] ),
        "Dim 2"VALUES ( 'Table1'[Dim2] )
    ),
    LastDate('Table1'[Date]),
    'Table1'[Dim5] = TRUE

 

RETURN

 

Calculate(

   SUM(Table1[Fact1]),

      Filter1

)

 

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi Kroth,

 

>>1. Am I typing something wrong in the DAX to accomplish a Calculated Table with only the unique combinations of Dim1 and Dim2?

Based on my test, you have written the calculate table in the VAR function, the formula will been limiting calculate range(only work on current row).

 

>> 2. Does passing a calculated table in a Calculate() parameter filter as I am expecting?

Yes, it is possible.

 

I have modified your formula, please follow below steps:

1. Create table.

 Capture.PNG

2. Modify your measure to match my table.

Test your calculate table formula: (It works well)

 Capture2.PNG

Measure = var fitler1 = CALCULATETABLE (

    ADDCOLUMNS (

        VALUES ( test[Column1] ),

        "Column2", VALUES ( test[Column2] )

    ),

    LastDate(test[Date]),

   test[Column5] = TRUE)

   return 

   Calculate(

   SUM(test[Column2]),

fitler1

)

 

3. Add a calculate column to display the result.

 Capture3.PNG

It seems that filter ‘LastDate(test[Date])’ not work. Since you put the code of calculate table in the VAR function, the formula will been limiting calculate range on current row.

 

4. Modify your code to fix this issue.

Measure = var fitler1 = CALCULATETABLE (

    ADDCOLUMNS (

        VALUES ( test[Column1] ),

        "Column2", VALUES ( test[Column2] )

    ),

    LastDate(ALL(test[Date])),

   test[Column5] = TRUE)

   return 

   Calculate(

   SUM(test[Column2]),

fitler1

)

 Capture4.PNG

 

Notice: The variable can store the table, but it can't get the columns directly, you can use filter or selectcolumns function to get columns which in the variable table.

 

Sample:

filter(filer1, [Column1] <> blank)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi Kroth,

 

>>1. Am I typing something wrong in the DAX to accomplish a Calculated Table with only the unique combinations of Dim1 and Dim2?

Based on my test, you have written the calculate table in the VAR function, the formula will been limiting calculate range(only work on current row).

 

>> 2. Does passing a calculated table in a Calculate() parameter filter as I am expecting?

Yes, it is possible.

 

I have modified your formula, please follow below steps:

1. Create table.

 Capture.PNG

2. Modify your measure to match my table.

Test your calculate table formula: (It works well)

 Capture2.PNG

Measure = var fitler1 = CALCULATETABLE (

    ADDCOLUMNS (

        VALUES ( test[Column1] ),

        "Column2", VALUES ( test[Column2] )

    ),

    LastDate(test[Date]),

   test[Column5] = TRUE)

   return 

   Calculate(

   SUM(test[Column2]),

fitler1

)

 

3. Add a calculate column to display the result.

 Capture3.PNG

It seems that filter ‘LastDate(test[Date])’ not work. Since you put the code of calculate table in the VAR function, the formula will been limiting calculate range on current row.

 

4. Modify your code to fix this issue.

Measure = var fitler1 = CALCULATETABLE (

    ADDCOLUMNS (

        VALUES ( test[Column1] ),

        "Column2", VALUES ( test[Column2] )

    ),

    LastDate(ALL(test[Date])),

   test[Column5] = TRUE)

   return 

   Calculate(

   SUM(test[Column2]),

fitler1

)

 Capture4.PNG

 

Notice: The variable can store the table, but it can't get the columns directly, you can use filter or selectcolumns function to get columns which in the variable table.

 

Sample:

filter(filer1, [Column1] <> blank)

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

Helpful resources

Announcements
MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Urdu Hindi D365 Bootcamp 768x460.png

Urdu Hindi D365 Bootcamp

Dont miss our very own April Dunnam’s The Developer Guide to the Galaxy! Find out what the Power Platform has to offer for the traditional developer.

Top Solution Authors
Top Kudoed Authors