Forum Discussion
Converting SQL into DAX...
- 3 years ago
Hi yjk3140
Final solution is as followsPaused Jobs = SUMX ( VALUES ( 'table1'[job_id] ), VAR MaxDate = CALCULATE ( MAX ( 'table1'[datetime1] ) ) VAR LastRecord = FILTER ( CALCULATETABLE ( 'table1' ), 'table1'[datetime1] = MaxDate && 'table1'[job_active_status] = "PAUSED" ) VAR Result = IF ( NOT ISEMPTY ( LastRecord ), 1 ) RETURN Result ) - 3 years ago
Anonymous
Ok, please tryCASH_IPD = COUNTROWS ( CALCULATETABLE ( SUMMARIZE ( BI_OSR_Revenues, BI_OSR_Revenues[Encounter_No], BI_OSR_Revenues[Payment_TypeName], BI_OSR_Revenues[InvoiceNo] ), BI_OSR_Revenues[Tran_Month] = 3, BI_OSR_Revenues[Tran_Year] = 2022, BI_OSR_Revenues[Payment_TypeName] = "CASH (IPD)", NOT ISBLANK ( BI_OSR_Revenues[admission_Date] ) ) )
Hi tamerj1, tanks for your resoponse 🙂
I tried your query, but it gives me blank as a result...
do you think this dax query makes sense to get the correct result?
Apologies. It was too late last night and seems that I missed one small detail. Please use
Paused Jobs =
SUMX (
VALUES ( 'Table'[job_id] ),
VAR MaxDate =
CALCULATE ( MAX ( 'Table'[timestamp] ) )
VAR LastRecord =
CALCULATETABLE ( 'Table', 'Table'[timestamp] = MaxDate )
VAR LastStatus =
MAXX ( LastRecord, 'Table'[status] )
RETURN
IF ( LastStatus = "PAUSED", 1 )
)
and yes, for each job id we are finding the max date then we count it only if it is PAUSED
- yjk31403 years agoHelper I
Hi tamerj1! your DAX query looks logically correct and smart but I don't think MAX function works for the date column here..I'm not getting any result but blank.
Do you think there is another approach to solve this query that I can try?
Thank you so much for your help!
- tamerj13 years agoCommunity Champion
Hi yjk3140
Just now I've prepared a sample file and it works just fine. However, this for sure depends of the filter context. The details that you might think they don't matter they actually do.- yjk31403 years agoHelper I
Hi tamerj1 yes the query looks really clear but I'm not sure why it doesn't work on my dataset...
This is a screenshot of the actual table I have below
do you think the format of the date matters here..? if so, is there anyway to get the result I want with the timestamps in this format?
really appreciate your help..!