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
slanka
Helper I
Helper I

Filter/Compare column values with headers

Mates,

 

My data is in below structure,

 

EmpNameStartDateDateEndate20152016201720182019
Emp12/25/20183/31/201911111
Emp24/19/201522/12/201811111
Emp310/12/201515/08/201711111

 

 

But, I want to see the the data as below,

 

EmpNameStartDateDateEndate20152016201720182019
Emp12/25/20183/31/2019   11
Emp24/19/201522/12/20181111 
Emp310/12/201515/08/2017111  

 

Flag (1) for each employee based on their Year(Min StartDate & Max EndDate). If both Years are same, then Flag should appear only in that respective Year. If StartDate & EndDate are in different Years, then Flag should spread across all the Years.

 

I am trying to figure out if there is a way to compare column value from StartDate with Header and generate the flag if it matches. Appreciate any help!

 

 

 

 

 

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

hi, @slanka 

You could try this way in Edit Queries:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tMFTSUTLSNzLVNzIwtACyjfWNDUFsSyDbEAPH6oA1GQE5JvqGliCFpiAJoAlGMBNw6jIGcQz0DY1g2gws9A3BFptj1xYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [EmpName = _t, StartDate = _t, DateEndate = _t, #"2015" = _t, #"2016" = _t, #"2017" = _t, #"2018" = _t, #"2019" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EmpName", type text}, {"StartDate", type date}, {"DateEndate", type date}, {"2015", Int64.Type}, {"2016", Int64.Type}, {"2017", Int64.Type}, {"2018", Int64.Type}, {"2019", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"2015", "2016", "2017", "2018", "2019"}),
    #"Inserted Year" = Table.AddColumn(#"Removed Columns", "Year", each Date.Year([StartDate]), Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Inserted Year",{{"Year", "StartYear"}}),
    #"Inserted Year1" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([DateEndate]), Int64.Type),
    #"Renamed Columns1" = Table.RenameColumns(#"Inserted Year1",{{"Year", "EndYear"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns1", "Year", each List.Buffer({2010..2020})),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Year"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "tag", each if [Year] >= [StartYear] and[Year]<=[EndYear] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([tag] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"StartYear", "EndYear"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns1", {{"Year", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns1", {{"Year", type text}}, "en-US")[Year]), "Year", "tag", List.Count),
    #"Reordered Columns" = Table.ReorderColumns(#"Pivoted Column",{"EmpName", "StartDate", "DateEndate", "2015", "2016", "2017", "2018", "2019"})
in
    #"Reordered Columns"

For example:

3.JPG4.JPG

and here is pbix file, please try it.

 

Best Regards,

Lin

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

4 REPLIES 4
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Not able to download the file you shared. Can you pls check once.

Hi,

That link is working just fine.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-lili6-msft
Community Support
Community Support

hi, @slanka 

You could try this way in Edit Queries:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs0tMFTSUTLSNzLVNzIwtACyjfWNDUFsSyDbEAPH6oA1GQE5JvqGliCFpiAJoAlGMBNw6jIGcQz0DY1g2gws9A3BFptj1xYLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [EmpName = _t, StartDate = _t, DateEndate = _t, #"2015" = _t, #"2016" = _t, #"2017" = _t, #"2018" = _t, #"2019" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"EmpName", type text}, {"StartDate", type date}, {"DateEndate", type date}, {"2015", Int64.Type}, {"2016", Int64.Type}, {"2017", Int64.Type}, {"2018", Int64.Type}, {"2019", Int64.Type}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"2015", "2016", "2017", "2018", "2019"}),
    #"Inserted Year" = Table.AddColumn(#"Removed Columns", "Year", each Date.Year([StartDate]), Int64.Type),
    #"Renamed Columns" = Table.RenameColumns(#"Inserted Year",{{"Year", "StartYear"}}),
    #"Inserted Year1" = Table.AddColumn(#"Renamed Columns", "Year", each Date.Year([DateEndate]), Int64.Type),
    #"Renamed Columns1" = Table.RenameColumns(#"Inserted Year1",{{"Year", "EndYear"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns1", "Year", each List.Buffer({2010..2020})),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Year"),
    #"Added Custom1" = Table.AddColumn(#"Expanded Custom", "tag", each if [Year] >= [StartYear] and[Year]<=[EndYear] then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([tag] = 1)),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"StartYear", "EndYear"}),
    #"Pivoted Column" = Table.Pivot(Table.TransformColumnTypes(#"Removed Columns1", {{"Year", type text}}, "en-US"), List.Distinct(Table.TransformColumnTypes(#"Removed Columns1", {{"Year", type text}}, "en-US")[Year]), "Year", "tag", List.Count),
    #"Reordered Columns" = Table.ReorderColumns(#"Pivoted Column",{"EmpName", "StartDate", "DateEndate", "2015", "2016", "2017", "2018", "2019"})
in
    #"Reordered Columns"

For example:

3.JPG4.JPG

and here is pbix file, please try it.

 

Best Regards,

Lin

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

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.