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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
yannkonin
Frequent Visitor

Dax measure : Counting Rows for the Next Day - Help Needed!

I'm having trouble counting rows for the next day using my DAX code. Can someone please help me understand why the "NuitMatinCount" isn't returning any results?


I'd appreciate any insights into why the "NuitMatinCount" variable isn't providing the expected results. Thanks in advance!
Here's my DAX code:

 

Effectif Nuit =
VAR CurrentDate = MAX(data_chargeuses[Date])
VAR Next = (CurrentDate + 1)
VAR NuitSoirCount =
CALCULATE(
DISTINCTCOUNT(data_chargeuses[Nom Conducteur]),
data_chargeuses[Shift] = "Nuit-Soir",
data_chargeuses[Date] = CurrentDate
)
VAR NuitMatinCount = CALCULATE(
DISTINCTCOUNT(data_chargeuses[Nom Conducteur]),
data_chargeuses[Shift] = "Nuit-Matin",
data_chargeuses[Date] = Next
)

RETURN
NuitSoirCount + NuitMatinCount

 

 


 

1 ACCEPTED SOLUTION
yannkonin
Frequent Visitor

Thank you very much, based on your response here is the solution i found

Effectif Nuit =
-- This DAX measure, which we will call "TotalNightDrivers", is used to calculate the number of separate drivers working "Night-evening" and "Night-morning" on the selected dates.

VAR SelectedDates =
    VALUES('Calendar'[Date]) -- This variable creates a table of all dates selected from the 'Calendar' table.
VAR ConducteursNuit =
    FILTER (
        ALLSELECTED('data_chargeuses'),  -- Applies filter to all selected rows (in case of global filter) of 'data_chargeuses'.
        (data_chargeuses[Shift] = "Nuit-soir" || data_chargeuses[Shift] = "Nuit-matin") &&
        data_chargeuses[AdjustedDate] IN SelectedDates
    )
RETURN
    COUNTROWS (
        SUMMARIZE (
            ConducteursNuit, -- Use the ConducteursNuit table directly after applying the filters
            data_chargeuses[Nom Conducteur]
           
        )
    )



here is the code for ajustedDate

AdjustedDate =
-- This calculated column, which we will call "AdjustedDate," is used to adjust the date based on the shift.

-- If the shift is "Night-morning," the date is shifted one day backward.
-- This accounts for drivers working overnight into the morning.

IF (
data_chargeuses[Shift] = "Nuit-matin",
data_chargeuses[Date] - 1,
data_chargeuses[Date]
)

 

View solution in original post

2 REPLIES 2
yannkonin
Frequent Visitor

Thank you very much, based on your response here is the solution i found

Effectif Nuit =
-- This DAX measure, which we will call "TotalNightDrivers", is used to calculate the number of separate drivers working "Night-evening" and "Night-morning" on the selected dates.

VAR SelectedDates =
    VALUES('Calendar'[Date]) -- This variable creates a table of all dates selected from the 'Calendar' table.
VAR ConducteursNuit =
    FILTER (
        ALLSELECTED('data_chargeuses'),  -- Applies filter to all selected rows (in case of global filter) of 'data_chargeuses'.
        (data_chargeuses[Shift] = "Nuit-soir" || data_chargeuses[Shift] = "Nuit-matin") &&
        data_chargeuses[AdjustedDate] IN SelectedDates
    )
RETURN
    COUNTROWS (
        SUMMARIZE (
            ConducteursNuit, -- Use the ConducteursNuit table directly after applying the filters
            data_chargeuses[Nom Conducteur]
           
        )
    )



here is the code for ajustedDate

AdjustedDate =
-- This calculated column, which we will call "AdjustedDate," is used to adjust the date based on the shift.

-- If the shift is "Night-morning," the date is shifted one day backward.
-- This accounts for drivers working overnight into the morning.

IF (
data_chargeuses[Shift] = "Nuit-matin",
data_chargeuses[Date] - 1,
data_chargeuses[Date]
)

 

Dangar332
Memorable Member
Memorable Member

Hi, @yannkonin 

 you should try 

add new column which define nextdate 

nextdate = 
var currentdate = data_chargeuses[Date]

var nextdate = minx(filter(data_chargeuses, data_chargeuses[Date]>currentdate), data_chargeuses[Date])

return  nextdate

 

and after adding new column you compare

 

Effectif Nuit =
VAR CurrentDate = MAX(data_chargeuses[Date])
VAR NuitSoirCount =
CALCULATE(
DISTINCTCOUNT(data_chargeuses[Nom Conducteur]),
data_chargeuses[Shift] = "Nuit-Soir",
data_chargeuses[Date] = CurrentDate
)
VAR NuitMatinCount = CALCULATE(
DISTINCTCOUNT(data_chargeuses[Nom Conducteur]),
data_chargeuses[Shift] = "Nuit-Matin",
data_chargeuses[Date] = nextdate       ------ nextdate which calculate as new column  and compare here with date
)

RETURN
NuitSoirCount + NuitMatinCount

 

 

Did i answer your question? Mark my post as a solution which help other people to find  fast and easily.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors