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

Power query formula help

Hi all,

 

I have a set of data that requires me to set up personnel that is active/inactive.

 

The dataset is about a set of professional that took exam on certain timeframe.

 

The dataset sample are shown as follow

Exam SessionName
Dec-23A
Jun-23A
Dec-22A
Jun-23B
Dec-22B
Dec-22C
Jun-23D
Jun-22E

The expected output are attached as image below.

 
 

rando230_0-1713411608800.png

 

As you can see, Candidate C and E are consider as inactive because they are not taking exam on dec 23 and jun 23. However, since this excel is going to be update constantly, the date of dec 23 will move to jun 24 when the next result comes in. hence there will be a new col and the condition will change according to that.

 

With the following condition, how should I create my formula for it in excel and even better, for power query instead?

4 REPLIES 4
dufoq3
Super User
Super User

Hi @profilewatercli, check this.

 

Result

dufoq3_0-1713432394406.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcklN1jUyVtJRclSK1YlW8irNQ+aCZY0wZZ1QZdG4zqiKXRBckKyrUmwsAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Exam Session" = _t, Name = _t]),
    #"Grouped Rows" = Table.Group(Source, {"Name"}, {{"All", each _, type table [Exam Session=nullable text, Name=nullable text]}}),
    #"Added Helper" = Table.AddColumn(#"Grouped Rows", "Helper", each 1, Int64.Type),
    #"Expanded All" = Table.ExpandTableColumn(#"Added Helper", "All", {"Exam Session"}, {"Exam Session"}),
    #"Added DateHelper" = Table.AddColumn(#"Expanded All", "DateHelper", each Date.FromText([Exam Session] & "-1", [Format="MMM-yy-d", Culture="en-US"]), type date),
    #"Sorted Rows" = Table.Sort(#"Added DateHelper",{{"DateHelper", Order.Descending}}),
    #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"DateHelper"}),
    #"Pivoted Column" = Table.Pivot(#"Removed Columns", List.Distinct(#"Removed Columns"[#"Exam Session"]), "Exam Session", "Helper"),
    #"Added Status" = Table.AddColumn(#"Pivoted Column", "Status", each 
        [ a = List.RemoveNulls(List.FirstN(Record.ToList(Record.RemoveFields(_, "Name")),2)),
          b = if List.Count(a) > 0 then "Active" else "Inactive"
        ][b], type text)
in
    #"Added Status"

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi there, I tried running your formula using an updated data as below.

Exam SessionName
Dec-23A
Jun-23A
Dec-22A
Jun-23B
Dec-22B
Dec-22C
Jun-23D
Jun-22E
Jun-24C
Jun-24E

However, the formula doesnt sync as the updated version. It's still showing Dec-23, Jun-23, Dec-22 and Jun-22 as follows.

profilewatercli_0-1713433627487.png

My final plan if to have a slicer selecting the session (datemonth) and showing the candidate if its active or non-active

profilewatercli_1-1713433735711.png

 

Maybe you want something like this (I've attached pbix file):

dufoq3_2-1713441112016.png

 

Filtered Dec-23:

dufoq3_3-1713441129603.png


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Hi, it works. I've updated Source data:

dufoq3_0-1713434325296.png

 

Result:

dufoq3_1-1713434342721.png

 

But maybe I don't understand what do you really need. Could you upload your data to google drive for example and provide a link?


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

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
Top Kudoed Authors