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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

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
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.