Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
yjk3140
Helper I
Helper I

Converting SQL into DAX...

Hi,

I have written the sql query below

SELECT count(job_id) FROM (SELECT distinct job_id,status,DENSE_RANK over() partition by job_id order by timestamp desc AS rn FROM table1) t2 WHERE t2.rn = 1 and where t2.status = "PAUSED"

to get the number of paused jobs by getting the latest status of the each job_id. I have duplicate values in the table, so I can't use LASTDATE and MAX also didn't work to get the correct result.

 

Convert SQL query into DAX query for PowerBI visual - Stack Overflow

 

this is my question posted in StackOverflow.

the solutions I got don't meet my requirements 100%

Just wondering if anyone knows how to convert that sql query to DAX.

 

I'm doing this in direct query mode so there are some limitations as well..

thanks in advance!

2 ACCEPTED SOLUTIONS
tamerj1
Community Champion
Community Champion

Hi @yjk3140 
Final solution is as follows

 

 

Paused 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
)

 

 

View solution in original post

@Anonymous 
Ok, please try

CASH_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] )
    )
)

View solution in original post

29 REPLIES 29

Hi @tamerj1 , 

I tried to use this query below to count the # of the jobs

Paused Jobs =
VAR MaxDate =
        CALCULATE(MAX ( 'table1'[timestamp] ))
VAR LastRecord =
        CALCULATETABLE ( 'table1', 'table1'[timestamp] = MaxDate )
VAR LastStatus =
        MAXX ( LastRecord, 'table1[job_status] )
VAR countid = CALCULATE( DISTINCTCOUNT(table1[job_id]), LastStatus = "PUASED")
 RETURN countid
 
and it's throwing the error below
The True/False expression does not specify a column. Each True/False expressions used as a table filter expression must refer to exactly one column
 
How can I fix it? 😕
tamerj1
Community Champion
Community Champion

Hi @yjk3140 
would you like to connect via teams or zoom? I have some time now

Hi @tamerj1  sure! I just created the zoom meeting and ID is 399 024 9510

tamerj1
Community Champion
Community Champion

@yjk3140 
I'll join in 5min

sure thank you 🙂

tamerj1
Community Champion
Community Champion

@yjk3140 

Asking for meeting passcode 

Hi @tamerj1! could you join again? the meeting ended because of the subscription issue..I just started the same one

///

tamerj1
Community Champion
Community Champion

@yjk3140 

Please send a new link

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.