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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
JP8991
Advocate II
Advocate II

Counting Items in Dimension Table based on Date

Hello,

Probably a really simple one but my brain is a little fried today.

I am trying to count the number centres in my dimension table however want to account for closures (Divestment Date) so for example a centre closes in 2020 so it would be present in 2019 and 2020 but not present in 2021 and 2022.

JP8991_0-1673242653845.png

 

Trying to get the below table to reflect the closed centres, calendar year is taken from the Calendar table above.

JP8991_1-1673242677707.png

 

 

1 ACCEPTED SOLUTION

Hi @JP8991 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1673335887605.png

vtangjiemsft_1-1673335916611.png

 

(2) We can create a measure. 

Centres = 
var _a=
CALCULATE (
    COUNTROWS ( Centres ),
    FILTER (
        ALL ( Centres[Divestment Date] ),
        Centres[Divestment Date] <= MAX ( Centres[Divestment Date] )
    )
    
)
var _b=COUNTROWS(FILTER(ALL('Centres'),'Centres'[Divestment Date]))
return 
_a-_b

(3) Then the result is as follows.

vtangjiemsft_2-1673335986482.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

View solution in original post

4 REPLIES 4
danextian
Super User
Super User

Hi @JP8991 ,

 

Your screenshot doesn't show the relationship between Centres and Calendar but if you're getting the same figure for all calendar years then mostly  likely that there isn't. You can try this as a measure but still won't show the correct number if you use calendar years and there isn't a relationship between the two tables

=
CALCULATE (
    COUNTROWS ( Centres ),
    FILTER (
        ALL ( Centers[Divestment Date] ),
        Centers[Divestment Date] <= MAX ( Centers[Divestment Date] )
    )
)









Did I answer your question? Mark my post as a solution!


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.

Thanks, really appreciate it, however it isn't quite working.

 

Centres = 
CALCULATE (
    COUNTROWS ( Centres ),
    FILTER (
        ALL ( Centres[Divestment Date] ),
        Centres[Divestment Date] <= MAX ( Centres[Divestment Date] )
    ),
    USERELATIONSHIP ( 'Calendar'[Date], Centres[Divestment Date] )
)


Using the above code I am getting the table below which is counting the number of closed Centres, what I am after is the number opposite to that, I am after the amount that were open.

So in 2019 it would be 45 minus total, in 2020 it would be 45 + 7 minus total etc etc.

JP8991_0-1673312531470.png




Hi @JP8991 ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data.  

vtangjiemsft_0-1673335887605.png

vtangjiemsft_1-1673335916611.png

 

(2) We can create a measure. 

Centres = 
var _a=
CALCULATE (
    COUNTROWS ( Centres ),
    FILTER (
        ALL ( Centres[Divestment Date] ),
        Centres[Divestment Date] <= MAX ( Centres[Divestment Date] )
    )
    
)
var _b=COUNTROWS(FILTER(ALL('Centres'),'Centres'[Divestment Date]))
return 
_a-_b

(3) Then the result is as follows.

vtangjiemsft_2-1673335986482.png

 

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

amitchandak
Super User
Super User

@JP8991 , Seem like join is missing between Divestment Date, or create an inactive join and userelationship

https://radacad.com/userelationship-or-role-playing-dimension-dealing-with-inactive-relationships-in...

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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