Forum Discussion
Convert SQL query to DAX
- 1 year ago
SG2015 - I'm not sure you understand how calculated tables work. They are not computed "on the fly" as people interact with the data in a report. They are calculated at the point of a refresh, but after all of the transformations are complete in Power Query. The means they are less efficient for the data model and not subjected to the same compression algorithms that tables created in Power Query are, you would actually be better off creating an aggregated table in Power Query.
However, if you would like to make this as a calculated table, here is the DAX:
CALCULATETABLE ( SUMMARIZE ( 'Table', 'Table'[ID], 'Table'[BOOKING_DATE], "Revenue", CALCULATE ( SUM ( 'Table'[BOOK_AMOUNT] ), KEEPFILTERS ( 'Table'[POS] IN { "A", "B", "C", "D", "E", "F" } ) ), "Cost", CALCULATE ( SUM ( 'Table'[BOOK_AMOUNT] ), KEEPFILTERS ( 'Table'[POS] = "X" ) ) ), 'Table'[Column1] = "NEW" )If this works, please mark it as the solution for the visibility of others.
SG2015 - I'm not sure you understand how calculated tables work. They are not computed "on the fly" as people interact with the data in a report. They are calculated at the point of a refresh, but after all of the transformations are complete in Power Query. The means they are less efficient for the data model and not subjected to the same compression algorithms that tables created in Power Query are, you would actually be better off creating an aggregated table in Power Query.
However, if you would like to make this as a calculated table, here is the DAX:
CALCULATETABLE (
SUMMARIZE (
'Table',
'Table'[ID],
'Table'[BOOKING_DATE],
"Revenue",
CALCULATE (
SUM ( 'Table'[BOOK_AMOUNT] ),
KEEPFILTERS ( 'Table'[POS] IN { "A", "B", "C", "D", "E", "F" } )
),
"Cost", CALCULATE ( SUM ( 'Table'[BOOK_AMOUNT] ), KEEPFILTERS ( 'Table'[POS] = "X" ) )
),
'Table'[Column1] = "NEW"
)
If this works, please mark it as the solution for the visibility of others.
Thank you Mark. I will give it another thought.
But for now, this is exactly what I would need. Thank you very much.
Best, Simon