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
Rt0790
Regular Visitor

Need Help_Dax

Hi All, I have a dataset that is getting dates list between start date time and end date time and students that are scheduled for courses, 

 

start datetimeend datetimeStudentIDList datesCoursesScheduled
11/16/2022 12:06pm2/28/2023 12:00pm151/10/2023MathTRUE
11/16/2022 12:06pm2/28/2023 12:00pm151/10/2023ChemTRUE

 

 

created a new column "scheduled" to check if a student is scheduled for a course at 8 am everyday by using 

 

"at 8am = var _1 = date(year(list dates),month(list dates),day(list dates)+TIME (8,0,0)
Return
IF ( _1 <= end datetime && _1 >= start date time || _1-1 < end datetime && _1-1 >= start datetime, "TRUE","FALSE") "

 

My question is if a student is schedueld for more than one subject at the same time on any given day I want CHEM to be TRUE and not math 

 

Expected result

 

start datetimeend datetimeStudentIDList datesCoursesScheduled
11/16/2022 12:06pm2/28/2023 12:00pm151/10/2023MathFALSE
11/16/2022 12:06pm2/28/2023 12:00pm151/10/2023ChemTRUE

 

Thanks in advance

Really appreciate any help.

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

Hi @Rt0790 ,

Please try to create a new column with below dax formula:

Column =
VAR ed = [end datetime]
VAR sd = [start datetime]
VAR _id = [StudentID]
VAR cse = [Courses]
VAR tmp =
    SUMMARIZE (
        'Table',
        'Table'[StudentID],
        'Table'[List dates],
        'Table'[start datetime],
        'Table'[end datetime],
        "Ctn", COUNTROWS ( 'Table' )
    )
VAR tmp1 =
    CALCULATETABLE ( VALUES ( 'Table'[StudentID] ), FILTER ( tmp, [Ctn] >= 2 ) )
VAR _1 =
    DATE ( YEAR ( [List dates] ), MONTH ( [List dates] ), DAY ( [List dates] ) + TIME ( 8, 0, 0 ) )
VAR _flg =
    IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "FALSE" )
RETURN
    SWITCH (
        TRUE (),
        _id
            IN tmp1
            && cse = "Chem",
            IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "False" ),
        _id
            IN tmp1
            && cse <> "Chem", "False",
        NOT ( _id IN tmp1 ),
            IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "FALSE" )
    )

vbinbinyumsft_0-1679982372235.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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-binbinyu-msft
Community Support
Community Support

Hi @Rt0790 ,

Please try to create a new column with below dax formula:

Column =
VAR ed = [end datetime]
VAR sd = [start datetime]
VAR _id = [StudentID]
VAR cse = [Courses]
VAR tmp =
    SUMMARIZE (
        'Table',
        'Table'[StudentID],
        'Table'[List dates],
        'Table'[start datetime],
        'Table'[end datetime],
        "Ctn", COUNTROWS ( 'Table' )
    )
VAR tmp1 =
    CALCULATETABLE ( VALUES ( 'Table'[StudentID] ), FILTER ( tmp, [Ctn] >= 2 ) )
VAR _1 =
    DATE ( YEAR ( [List dates] ), MONTH ( [List dates] ), DAY ( [List dates] ) + TIME ( 8, 0, 0 ) )
VAR _flg =
    IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "FALSE" )
RETURN
    SWITCH (
        TRUE (),
        _id
            IN tmp1
            && cse = "Chem",
            IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "False" ),
        _id
            IN tmp1
            && cse <> "Chem", "False",
        NOT ( _id IN tmp1 ),
            IF ( _1 <= ed && _1 >= sd || _1 - 1 < ed && _1 - 1 >= sd, "TRUE", "FALSE" )
    )

vbinbinyumsft_0-1679982372235.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi, I tried this on a similar dataset and I get the following error, "Argument of function 'DATE' has the wrong data type or the result is too large or too small".

Peter_Beck
Resolver II
Resolver II

Hi -

One very way to do this, which I think is a bit crude but might work, is to group on the fields you have shown above in the Power Query editor, and add a row number for the Courses Scheduled subject. A technique for adding an index on groups is here:

 

https://radacad.com/create-row-number-for-each-group-in-power-bi-using-power-query

 

Then you would add a condition in your forumula to check to see if the index of the group was "1", which would correspond with "CHEM" in the grouping because it comes ahead of math. It isn't pretty but I think it would work.

 

Hope this helps,

 

Peter

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