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
Darko_Giac
Helper II
Helper II

Creating Categories Based on Order of Test Completion

Hi all!

 

I have what may be kind of a complex issue.

I'm currently working with a data set in power query and wondering whether there was any way (within either power query, if not perhaps within power pivot?) to create a flag that will place students in one of three 2 categories based on the ordre in which they completed a test.

For example, a student who completed an English test on August 20th, Math on the 24th and Science on the 28th would be categorized as a 1.

 

A student who completed an English test on August 20th, [B][I]Science[/I][/B] on the 24th and Math on the 28th would be categorized as a 2.

 

Attached are screenshots of a workbook containing a stripped down, modified sample of my data set as well as the result I would like to achieve.

 

Any suggestions would be greatly appreciated.

 

WorkingData.jpgDesiredResult.jpg

 

Thank you!

Darko

1 ACCEPTED SOLUTION
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Darko_Giac,

 

I'm not good at power query but I think you could achieve that use dax formula.

 

You coud create a calculated column with the dax formual below.

 

Column =
IF (
    AND (
        CALCULATE (
            MAX ( 'Table1'[Test] ),
            FILTER (
                'Table1',
                'Table1'[ID] = EARLIER ( Table1[ID] )
                    && 'Table1'[Date] = MIN ( 'Table1'[Date] )
            )
        )
            = "Math",
        CALCULATE (
            MAX ( 'Table1'[Test] ),
            FILTER (
                'Table1',
                'Table1'[ID] = EARLIER ( Table1[ID] )
                    && 'Table1'[Date] = MAX ( 'Table1'[Date] )
            )
        )
            = "Science"
    ),
    1,
    IF (
        AND (
            CALCULATE (
                MAX ( 'Table1'[Test] ),
                FILTER (
                    'Table1',
                    'Table1'[ID] = EARLIER ( Table1[ID] )
                        && 'Table1'[Date] = MIN ( 'Table1'[Date] )
                )
            )
                = "Math",
            CALCULATE (
                MAX ( 'Table1'[Test] ),
                FILTER (
                    'Table1',
                    'Table1'[ID] = EARLIER ( Table1[ID] )
                        && 'Table1'[Date] = MAX ( 'Table1'[Date] )
                )
            )
                = "English"
        ),
        2
    )
)

Here is the output.

 

Capture.PNG

 

If you still want to achieve that with power query, you could get help in TechNet forum.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
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

2 REPLIES 2
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @Darko_Giac,

 

I'm not good at power query but I think you could achieve that use dax formula.

 

You coud create a calculated column with the dax formual below.

 

Column =
IF (
    AND (
        CALCULATE (
            MAX ( 'Table1'[Test] ),
            FILTER (
                'Table1',
                'Table1'[ID] = EARLIER ( Table1[ID] )
                    && 'Table1'[Date] = MIN ( 'Table1'[Date] )
            )
        )
            = "Math",
        CALCULATE (
            MAX ( 'Table1'[Test] ),
            FILTER (
                'Table1',
                'Table1'[ID] = EARLIER ( Table1[ID] )
                    && 'Table1'[Date] = MAX ( 'Table1'[Date] )
            )
        )
            = "Science"
    ),
    1,
    IF (
        AND (
            CALCULATE (
                MAX ( 'Table1'[Test] ),
                FILTER (
                    'Table1',
                    'Table1'[ID] = EARLIER ( Table1[ID] )
                        && 'Table1'[Date] = MIN ( 'Table1'[Date] )
                )
            )
                = "Math",
            CALCULATE (
                MAX ( 'Table1'[Test] ),
                FILTER (
                    'Table1',
                    'Table1'[ID] = EARLIER ( Table1[ID] )
                        && 'Table1'[Date] = MAX ( 'Table1'[Date] )
                )
            )
                = "English"
        ),
        2
    )
)

Here is the output.

 

Capture.PNG

 

If you still want to achieve that with power query, you could get help in TechNet forum.

 

Best  Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks so much! Worked exactly like I had hoped!

 

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.