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

How to distinct count an column only on the first date in DAX?

I have a Table ('Table') with two Projects (ABC-10 and ABC-11) where an Project can occur over multiple dates due to having different Sub Project states and Companies.

ProjectSub ProjectCompanyDate
ABC-10      1A30/09/2021
ABC-10      2A30/09/2021
ABC-10      1B30/06/2022
ABC-10      1C30/09/2021
ABC-10      1D30/09/2021
ABC-10      2D30/08/2021
ABC-11      1A30/09/2021
ABC-11      2A30/09/2021
ABC-11      1B30/06/2022
ABC-11      1C30/09/2021
ABC-11      1D30/09/2021
ABC-11      2D30/01/2020

 

What I need:

- I would like to create one measure ([MyMeasure]) to distinct count the Project by the first Date at wich project occurred.

- I pretend that [MyMeasure] provides me the same approach based on the companies I select.

- This measure is needed for Bars Charts and table visuals.

 

This is the expected result if I select all companies:

DateMyMeasure
30/01/2020        1
30/08/2021        1

 

This is the expected result if I select the companies A and B :

DateMyMeasure
30/06/2022        2

 

I already create one measure wich provides me the right value if I don't select any company.

 

MyMeasure = 
VAR t =
    CALCULATETABLE(
        VALUES('Table'[Project])
        ,FILTER(
            'table'
            ,VAR dateInRow=[Date]
                RETURN  
                dateInRow=CALCULATE(
                           min('Table'[Date])
                           ,ALLEXCEPT('Table','Table'[Project]))))
var result = COUNTROWS(t)
return
result

 

gfvlopes_0-1671019515709.png

 

The problem is when I select one or more companies (A and B in this example) the maesure doesn't calculate the right value:

gfvlopes_1-1671019545396.png

How can I solve this?

Thank you!

1 ACCEPTED SOLUTION
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

I produced the following measure and I would say it works. What I do not get is why you expect 30/06/2022 when choosing A and B. WOuldnt it be 30/09/2021?

 

Here my measure: SampleM99106 is the name of your table

MyMeasure = 
var __FirstDateOfProject = 
    CALCULATETABLE(
        SUMMARIZE(SampleM99106,[Project],"FirstDate",FIRSTDATE(SampleM99106[Date])),
        ALLEXCEPT(SampleM99106,SampleM99106[Project],SampleM99106[Company])
    )

var __SelectedDate = SELECTEDVALUE(SampleM99106[Date])

var __Result =
    COUNTROWS(
        FILTER(__FirstDateOfProject,[FirstDate]=__SelectedDate)
    )

Return
__Result

 

Mikelytics_0-1671032564030.png

 

Best regards

Michael

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

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

Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

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

LinkedIn

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!

View solution in original post

2 REPLIES 2
Mikelytics
Resident Rockstar
Resident Rockstar

Hi @Anonymous 

 

I produced the following measure and I would say it works. What I do not get is why you expect 30/06/2022 when choosing A and B. WOuldnt it be 30/09/2021?

 

Here my measure: SampleM99106 is the name of your table

MyMeasure = 
var __FirstDateOfProject = 
    CALCULATETABLE(
        SUMMARIZE(SampleM99106,[Project],"FirstDate",FIRSTDATE(SampleM99106[Date])),
        ALLEXCEPT(SampleM99106,SampleM99106[Project],SampleM99106[Company])
    )

var __SelectedDate = SELECTEDVALUE(SampleM99106[Date])

var __Result =
    COUNTROWS(
        FILTER(__FirstDateOfProject,[FirstDate]=__SelectedDate)
    )

Return
__Result

 

Mikelytics_0-1671032564030.png

 

Best regards

Michael

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

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

Appreciate your thumbs up!

@ me in replies or I'll lose your thread.

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

LinkedIn

 

 

------------------------------------------------------------------
Visit my blog datenhungrig which I recently started with content about business intelligence and Power BI in German and English or follow me on LinkedIn!
Anonymous
Not applicable

Hey,

This approach works! Thank you!

Yes, sorry, my bad. The correct return for A and B companies is two projects on 30/09/2021.

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.

Top Solution Authors