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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
Anonymous
Not applicable

COUNTROWS Function

Hello,

please I cannot understand why the DAX query below give an empty result. In fact, the function inside the COUNTROWS works well and the result is a table. But the COUNTROWS doesn't work.  Please I need your help...

 

NumberPresentNov21_and_AbsentDec21 = COUNTROWS(

INTERSECT(

(SELECTCOLUMNS(VAR Tab_TransdateLastMonth= CALCULATETABLE(VS, MONTH(VS[TransDate])=12 && YEAR(VS[TransDate])=2021 && (VS[PatientStatus]="Defaulter"))

RETURN

SUMMARIZE(Tab_TransdateLastMonth

,VS[BaselineCode], VS[PatientStatus] , "LastRDVDate", MAX(VS[TransDate])),"BaselineCode", VS[BaselineCode]))

,

(SELECTCOLUMNS(VAR Tab_TransdateLastMonth= CALCULATETABLE(VS, MONTH(VS[TransDate])=11 && YEAR(VS[TransDate])=2021 && (VS[PatientStatus]="On Tx"|| VS[PatientStatus]="Transfered In" || VS[PatientStatus]="Restarted Tx" ))

RETURN

SUMMARIZE(Tab_TransdateLastMonth

,VS[BaselineCode], "DateLastRDV",  MAX(VS[TransDate])),"BaselineCode", VS[BaselineCode])

))

)

1 ACCEPTED SOLUTION

Sorry, I'd focussed on the SUMMARIZE and totally missed what the SELECTCOLUMNS was doing!

 

When you add the COUNTROWS in have you tried dropping the measure into a card on an empty page with no report filters set. Just wondering if something is already in the filter context.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hello bcdobbs,

your are right. There was a filter context in my file. The query works well in an empty file. 

Thanks once more. 

Regards

bcdobbs
Community Champion
Community Champion

Hi,


If I'm understanding when you materialise the two tables as calculated tables separatly you end up with an "DateLastRDV" in both. The first one will have max date from Dec 21 and the second from Nov 21.

 

That is then a problem when you use INTERSECT because it returns a table which has all the rows in the first table that are also in the second table. Because no row can have the same date in both tables you get an empty table returned.

 

If that isn't it can you supply some dummy data in a pbix?



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Anonymous
Not applicable

Hello bcdodds,

Thanks very much for your help.

In fact, the function INTERSECT has two parameters (tables). If you look deeply you will notice that each one of them(parameters) is a table with only one columns named "BaselineCode". The columns "DateLastRDV" are not kept in the both parameters of INTERSECT because I knew what you have just said, which is absolutely true (Look at SUMMARIZE).

Then the function INTERSECT works well when it is excuted without COUNTROWS. It returns a table with a single columns named "BaselineCode".

My challenge is to count the number of rows of the result of INTERSECT function; but the function COUNTROWS is not working.

I hope it is a little more clear now? If not, please come back to me.

Sorry, I'd focussed on the SUMMARIZE and totally missed what the SELECTCOLUMNS was doing!

 

When you add the COUNTROWS in have you tried dropping the measure into a card on an empty page with no report filters set. Just wondering if something is already in the filter context.



Ben Dobbs

LinkedIn | Twitter | Blog

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.