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
Anonymous
Not applicable

DAX end of month selection

image.png

 

I would like to write a DAX to count the number of 'yes' as shown in the column [one-year@work], which is not in the data model and i would like to avoid creating a calculated column. 

The DAX should check through the column [left] and find out if the date is 31.12 of the year (it could be any year 2018, 2019,...) or empty, both cases are to be evaluated as positive and counted. See my effort below.  Thankful for any pointers and solutions ...

SWITCH (
    TRUE ();
    VALUES ( table[Position] ) = "worker"; CALCULATE (
        CONTAINSSTRING ( data[Funktion]; "worker" );
        ISBLANK ( data[left] ) OR NOT(ISBLANK(endofmonth(data[left])))
    );

 

1 ACCEPTED SOLUTION
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following measure to meet your requirement,

 

Measure = 
SWITCH (
    TRUE(),
    MAX('Table'[Position])  = "worker",
    CALCULATE (
       CALCULATE(COUNT('Table'[Position]),'Table'[Position]="worker")
        ,FILTER('Table', ISBLANK('Table'[left]) || ENDOFYEAR('Table'[left]) = 'Table'[left]))
        )

 

The result like this,

 

DAX11.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

3 REPLIES 3
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

We can use the following measure to meet your requirement,

 

Measure = 
SWITCH (
    TRUE(),
    MAX('Table'[Position])  = "worker",
    CALCULATE (
       CALCULATE(COUNT('Table'[Position]),'Table'[Position]="worker")
        ,FILTER('Table', ISBLANK('Table'[left]) || ENDOFYEAR('Table'[left]) = 'Table'[left]))
        )

 

The result like this,

 

DAX11.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

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

AllisonKennedy
Super User
Super User

Not sure what this is counting and why you aren't using DATEDIFF, but could you try (as a MEASURE):

 

CountOneYr@Wk= COUNTROWS(FILTER(Table, ISBLANK(Table[left]) || ENDOFYEAR(Table[left]) = Table[left]))))

 

Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 

 

If you found this post helpful, please give Kudos.

I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 

https://sites.google.com/site/allisonkennedycv

 

 


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

Anonymous
Not applicable

@AllisonKennedy  thanks for your quick respond.  But it has to be done in a switch and calculate expression as i am working on a huge dashboard and dont want to change a lot.

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.