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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
nic_learner
Frequent Visitor

DAX measure to count all based on current year and month selected

Hi, I have a table with a date column (dd/mm/yyyy) and an ID column which covers a few years. I am trying to create a measure that counts all IDs of the year selected up to the month selected. 

This is the measure I have which works for year 1 but once I add another year, I starts counting all IDs regardless of the year:

Cumulative ID Selected Year=
CALCULATE(COUNT('TABLE'[ID]),
    FILTER(ALL('Date'),
        'Date'[Date] <= MAX('Date'[Date])
))
 
Here is an example of the data: if the month/year selected is may-22, the count should be 5 but if I select jan-23, the count should only be 1 as it is a different year.
DATEID
1/1/2022152914
1/2/2022128964
1/3/2022137373
1/4/2022126435
1/5/2022187769
1/6/2022181764
1/7/2022174921
1/8/2022149012
1/9/2022144947
1/10/2022150902
1/11/2022162587
1/12/2022155684
1/1/2023189936
 
Thanks!
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1676225002060.png

 

 

Jihwan_Kim_0-1676224981890.png

 

 

Cumulative ID Selected Year =
CALCULATE (
    COUNTROWS ( DISTINCT ( 'Table'[ID] ) ),
    WINDOW (
        1,
        ABS,
        0,
        REL,
        ALL ( 'Date'[Year], 'Date'[Month-Year], 'Date'[Month-Year sort] ),
        ORDERBY ( 'Date'[Month-Year sort], ASC ),
        KEEP,
        PARTITIONBY ( 'Date'[Year] )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

3 REPLIES 3
FreemanZ
Super User
Super User

hi @nic_learner 

 

try to add a year condition like:

Cumulative ID Selected Year=
CALCULATE(
    COUNT('TABLE'[ID]),
    FILTER(
         ALL('Date'),
        'Date'[Date] <= MAX('Date'[Date])
            &&YEAR('Date'[Date] = YEAR(MAX('Date'[Date]))
    )
)
Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

Jihwan_Kim_1-1676225002060.png

 

 

Jihwan_Kim_0-1676224981890.png

 

 

Cumulative ID Selected Year =
CALCULATE (
    COUNTROWS ( DISTINCT ( 'Table'[ID] ) ),
    WINDOW (
        1,
        ABS,
        0,
        REL,
        ALL ( 'Date'[Year], 'Date'[Month-Year], 'Date'[Month-Year sort] ),
        ORDERBY ( 'Date'[Month-Year sort], ASC ),
        KEEP,
        PARTITIONBY ( 'Date'[Year] )
    )
)

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hi Jihwan_Kim, that works. Thank you so much!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.