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
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
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