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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
zzzsou
Frequent Visitor

How to find distinct count on last 4weeks

Hello, I would like to use distinctcount function for the situation below 

here is the raw data.

 

In order to get the values, I made dax measures below and added a new column

but it did not work.

----------------------------------------------------------------------------------

CALCULATE(
    DISTINCTCOUNT('Table'[Recipe]),
    ALLEXCEPT('Table','Table'[Machine],'Table'[Week],'Table'[Recipe]),
                ('Table'[Week]<=MAX('Table'[Week]))&&
                ('Table'[Week]>MAX('Table'[Week])-4)
        )    

  ----------------------------------------------------------------------------------

 

So Could you kindly help me with this issue? 

 

 

Machine Week Recipe 

 

What I would like to get

= (distict value of recipes for each machine on last 4weeks) 

A 202301 a1 1 (=a1)
B 202301 b1 1
C 202301 c1 1
... ... .... ...
A 202302 a2 2 (=a1,a2)
A 202303 a2 2 (=a1,a2)
A 202304 a3 3 (=a1,a2,a3)
A 202305 a3 2 (=a2,a3)

 

 

Thank you in advance 

1 REPLY 1
lbendlin
Super User
Super User

use variables to calculate the current week. Use REMOVEFILTERS on the recipe. Note: This is a measure - could be a calculated column too if there are no filter impacts.

 

lbendlin_0-1684285676205.png

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors