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
masplin
Impactful Individual
Impactful Individual

Newbie to DAX Studio tables as variables

Hi

 

I have never used DAX Studio before but stuggling with one of my measures that isnt giving me the result I expect so trying to breakdown what is happening. 

 

Firstly I tested the TableVar statement using EVALUATE and generates the table I expect which is a row for each TimeKey (which are minutes) and count of users for each day

 

I want to feed this table into created a second table that works out the maximum over each minute within 15 minute windows (QtrHr). i can't work out how to use a table as a variable in DAX Studio as just errors.  Please can someone tel lme the right syntax so I output the table  with rows for each day, each qtrHr and the max of the previous table?

 

Thanks for any assitance

Mike 

DEFINE
TABLE
TableVar =
    ADDCOLUMNS (
        SUMMARIZE ( AdvisersOnCall,AdvisersOnCall[TimeKey],'Date'[Date],'Time'[QtrHr] ),
        "AdvisersOnCall", CALCULATE ( ( COUNT ( AdvisersOnCall[participantid] ) ) )
            
    )
EVALUATE
ADDCOLUMNS(
                       SUMMARIZE(TableVar,'Date'[Date],'Time'[QtrHr],[AdvisersOnCall]),
                        "QTRMAX",       MAX( [AdvisersOnCall])
                        )
3 ACCEPTED SOLUTIONS

If you wanted to see the output of that second table in DAX Studio you should be able to alter it as follows to see the output of the variable at the grand total level.

 

DEFINE 
VAR
TableVar =
    ADDCOLUMNS (
        SUMMARIZE ( AdvisersOnCall,AdvisersOnCall[TimeKey],'Date'[Date],'Time'[QtrHr] ),
        "AdvisersOnCall", CALCULATE ( ( COUNT ( AdvisersOnCall[participantid] ) ) )
         )
        
 VAR
 QtrMaX=       
ADDCOLUMNS(
                       SUMMARIZE(TableVar,'Date'[Date],'Time'[QtrHr],[AdvisersOnCall]),
                        "QTRMAX",       MAX( [AdvisersOnCall])
           )
EVALUATE QtrMaX         

But to achieve that output you've described I would have thought that you could do something like the following:

 

Measure = MAXX( VALUES( 'Time'[TimeKey]), CALCULATE( COUNTROWS( AdvisersOnCall ) ) )

 

View solution in original post

Sorry, that was a brain fade on my behalf. The calculated tables insert an implied EVALUATE at the top of the table expression so you can't include the explicit EVALUATE.

 

So you should be able to run the following in a calculated table:

Table = 

VAR
TableVar =
    ADDCOLUMNS (
        SUMMARIZE ( AdvisersOnCall,AdvisersOnCall[TimeKey],'Date'[Date],'Time'[QtrHr] ),
        "AdvisersOnCall", CALCULATE ( ( COUNT ( AdvisersOnCall[participantid] ) ) )
         )
        
 VAR
 QtrMaX=       
ADDCOLUMNS(
                       SUMMARIZE(TableVar,'Date'[Date],'Time'[QtrHr],[AdvisersOnCall]),
                        "QTRMAX",       MAX( [AdvisersOnCall])
           )
RETURN QtrMaX   

and the only difference in DAX Studio would be that you would need to explicitly add the EVALUATE at the top instead of the "Table ="

EVALUATE
VAR
TableVar =
    ADDCOLUMNS (
        SUMMARIZE ( AdvisersOnCall,AdvisersOnCall[TimeKey],'Date'[Date],'Time'[QtrHr] ),
        "AdvisersOnCall", CALCULATE ( ( COUNT ( AdvisersOnCall[participantid] ) ) )
         )
        
 VAR
 QtrMaX=       
ADDCOLUMNS(
                       SUMMARIZE(TableVar,'Date'[Date],'Time'[QtrHr],[AdvisersOnCall]),
                        "QTRMAX",       MAX( [AdvisersOnCall])
           )
RETURN QtrMaX   

The calculated table epressions are actually not as flexible as the full query syntax as they don't support the DEFINE statement.

View solution in original post

masplin
Impactful Individual
Impactful Individual

That's perfect thanks. all makes sense

 

Much appreciated

Mike

View solution in original post

12 REPLIES 12

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.

Top Solution Authors