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
Anonymous
Not applicable

Displaying 3 last values in comma separated list individually/calculate

Hi All, I have a list of devices with different software installation dates and versions.

 

melon327_0-1684606754013.png

It was originally multiple rows per version for the same device so I grouped it in Power Query.

I'm trying to return the, if available - The last 3 dates descending entries in the comma separated list for the BIOSVersions, BIOSDates, and BIOSStatuses. N, N-1, N-2. So maybe 6-9 Measures? or what would be the best approach. I am also trying to perform a datediff on the potentially three date values.

 

Essentially, I am trying to get an output like this:

melon327_0-1684617217408.png

(On further review, I think my grouping had an issue). 

This is my sample data.

Device SerialDevice NameLatest Bios VersionBIOSVersionsBIOSDatesBIOSStatuses
1a01.24.0004.05, Q70 Ver. 01.21.02, Q70 Ver. 01.04.05, Q70 Ver. 01.22.00, Q70 Ver. 01.07.00, Q70 Ver. 01.23.00, Q70 Ver. 01.15.00, Q70 Ver. 01.17.002022-08-01, 2018-11-16, 2022-09-15, 2019-04-15, 2022-12-09, 2020-12-28, 2021-08-05Old, Old, Old, Old, Old, Old, Old, Old
2b02.12.0000.30.00, 00.33.01, 00.41.00, 00.43.00, 02.11.012022-12-07, 2023-01-06, 2023-01-18, 2023-02-08, 2023-03-29Old, Old, Old, Old, Old
3c 0.00.2610/9/2020Unknown
4d01.13.01T95 Ver. 01.11.00, T95 Ver. 01.12.002022-10-17, 2023-01-03Old, Old
5e80.300.18, 80.282014-07-25, 2018-11-06Old, Old

Thank you in advance for any and all help.

1 ACCEPTED SOLUTION

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZTNbsMgDMdfpcq5INuQAE8x9bBdqh62tadNmbRLX38mdreoqgKeFARy/JPh74/jccBhP7zyAvQUPQAfeRt54+/p8zyc9g+dDgl3L5dvv2MbKIGTQ3QEmA1sEhuODmJli4EtHohtVDSugUUQGwQHlSWwsUvc6ICsLF87aNzJyrKtuhDrDFZ2FBtlh+Y7Z40bRWdCA1s0v1F1pn6WNEdEjuUysig54qCQrWzQ2iiq1Zqt57dWwzxwOiToa5gWu9UwDXazCFqsxoVRBcV+djMZLZb+3lus7FYiaxe+15/kUWMA+HCbC6kfCdIe3M9S4qGJRNRH5X7k9pasQ6eF0DJrUOaj9M8aiXw+S9XWJ3uaVKjfyfI8f8xf1/kf3rW2L7wyi7MQS4ETZzDVio2ra9y58kZZtLzrjNMP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Device Serial" = _t, #"Device Name" = _t, #"Latest Bios Version" = _t, biosmfgver = _t, biosdate = _t, biosstatus = _t]),
    #"Filtered Rows1" = Table.SelectRows(Source, each ([biosstatus] = "Old")),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows1",{"biosstatus"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Device Serial", type text}, {"Device Name", type text}, {"Latest Bios Version", type text}, {"biosmfgver", type text}, {"biosdate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Device Serial"}, {{"All", each _, type table [Device Serial=nullable text, Device Name=nullable text, Latest Bios Version=nullable text, biosmfgver=nullable text, biosdate=nullable date, biosstatus=nullable text]}}),
    biosdaterank = Table.TransformColumns(#"Grouped Rows",{"All", each Table.AddRankColumn(_,"Daterank",
    {"biosdate", Order.Descending},
    [RankKind = RankKind.Competition]
)}),
    #"Removed Columns" = Table.RemoveColumns(biosdaterank,{"Device Serial"}),
    #"Expanded All" = Table.ExpandTableColumn(#"Removed Columns", "All", {"Device Serial", "Device Name", "Latest Bios Version", "biosmfgver", "biosdate", "Daterank"}, {"Device Serial", "Device Name", "Latest Bios Version", "biosmfgver", "biosdate", "Daterank"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded All", each [Daterank] <= 3),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Device Serial", "Device Name", "Latest Bios Version", "Daterank"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns","bios","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","mfg","",Replacer.ReplaceText,{"Attribute"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Replaced Value1", {{"Daterank", type text}}, "en-IN"),{"Attribute", "Daterank"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    Datecolumns = Table.FromList(List.Select(Table.ColumnNames(#"Pivoted Column"), each Text.Contains(_,"date",Comparer.OrdinalIgnoreCase)), Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.AddColumn(Datecolumns, "Custom", each Value.Type(#date(2023,1,1))),
    datatypelist = List.Zip({#"Added Custom"[Column1],#"Added Custom"[Custom]}),
    Result = Table.TransformColumnTypes(#"Pivoted Column",datatypelist),
    #"Datediff 1" = Table.AddColumn(Result, "Date Diff 1", each Duration.Days([date 1] - [date 2]), Int64.Type),
    #"Datediff 2" = Table.AddColumn(#"Datediff 1", "Date Diff 2", each Duration.Days([date 2] - [date 3]), Int64.Type)
in
    #"Datediff 2"

Hope this helps.

Untitled.png


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

View solution in original post

7 REPLIES 7
Ahmedx
Super User
Super User

Ahmedx
Super User
Super User

you can get last 3 records in power query like this

 

List.LastN(
Text.Split([BIOSDates],","),3)

 

Screen Capture #1140.png

Ashish_Mathur
Super User
Super User

Hi,

I am not clear about he expected result.  Share the raw dataset and populate the table of expected results.


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

Hi, Apologies,  I couldn't find a file upload button.

https://we.tl/t-micPll22kt This is the file I can provide after grouping

https://we.tl/t-Tdl2Oh4PgD raw file.

I am trying to get the most recent 3 dates for a device, and the most 3 recent versions of the BIOS.

 

I think my grouping put them out of order somehow, sorry. This is the desired output mockup; Thank you.

Device SerialDevice NameLatest Bios VersionDate 1Version 1Date 2Version 2Date 3Version 3Date Diff 1Date Diff 2
1a01.24.0012/9/2022Q70 Ver. 01.23.009/15/2022Q70 Ver. 01.22.008/1/2022Q70 Ver. 01.21.0285.0045
2c02.12.003/29/2023 00.43.001/18/2023 00.41.001/18/202300.33.0170.000
3d 10/9/20200.00.26    N/A0
5e80.311/6/201880.287/25/20140.18  1565.000

Hi,

This M code works

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("nZTNbsMgDMdfpcq5INuQAE8x9bBdqh62tadNmbRLX38mdreoqgKeFARy/JPh74/jccBhP7zyAvQUPQAfeRt54+/p8zyc9g+dDgl3L5dvv2MbKIGTQ3QEmA1sEhuODmJli4EtHohtVDSugUUQGwQHlSWwsUvc6ICsLF87aNzJyrKtuhDrDFZ2FBtlh+Y7Z40bRWdCA1s0v1F1pn6WNEdEjuUysig54qCQrWzQ2iiq1Zqt57dWwzxwOiToa5gWu9UwDXazCFqsxoVRBcV+djMZLZb+3lus7FYiaxe+15/kUWMA+HCbC6kfCdIe3M9S4qGJRNRH5X7k9pasQ6eF0DJrUOaj9M8aiXw+S9XWJ3uaVKjfyfI8f8xf1/kf3rW2L7wyi7MQS4ETZzDVio2ra9y58kZZtLzrjNMP", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Device Serial" = _t, #"Device Name" = _t, #"Latest Bios Version" = _t, biosmfgver = _t, biosdate = _t, biosstatus = _t]),
    #"Filtered Rows1" = Table.SelectRows(Source, each ([biosstatus] = "Old")),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows1",{"biosstatus"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Removed Columns1",{{"Device Serial", type text}, {"Device Name", type text}, {"Latest Bios Version", type text}, {"biosmfgver", type text}, {"biosdate", type date}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Device Serial"}, {{"All", each _, type table [Device Serial=nullable text, Device Name=nullable text, Latest Bios Version=nullable text, biosmfgver=nullable text, biosdate=nullable date, biosstatus=nullable text]}}),
    biosdaterank = Table.TransformColumns(#"Grouped Rows",{"All", each Table.AddRankColumn(_,"Daterank",
    {"biosdate", Order.Descending},
    [RankKind = RankKind.Competition]
)}),
    #"Removed Columns" = Table.RemoveColumns(biosdaterank,{"Device Serial"}),
    #"Expanded All" = Table.ExpandTableColumn(#"Removed Columns", "All", {"Device Serial", "Device Name", "Latest Bios Version", "biosmfgver", "biosdate", "Daterank"}, {"Device Serial", "Device Name", "Latest Bios Version", "biosmfgver", "biosdate", "Daterank"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded All", each [Daterank] <= 3),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Filtered Rows", {"Device Serial", "Device Name", "Latest Bios Version", "Daterank"}, "Attribute", "Value"),
    #"Replaced Value" = Table.ReplaceValue(#"Unpivoted Other Columns","bios","",Replacer.ReplaceText,{"Attribute"}),
    #"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","mfg","",Replacer.ReplaceText,{"Attribute"}),
    #"Merged Columns" = Table.CombineColumns(Table.TransformColumnTypes(#"Replaced Value1", {{"Daterank", type text}}, "en-IN"),{"Attribute", "Daterank"},Combiner.CombineTextByDelimiter(" ", QuoteStyle.None),"Merged"),
    #"Pivoted Column" = Table.Pivot(#"Merged Columns", List.Distinct(#"Merged Columns"[Merged]), "Merged", "Value"),
    Datecolumns = Table.FromList(List.Select(Table.ColumnNames(#"Pivoted Column"), each Text.Contains(_,"date",Comparer.OrdinalIgnoreCase)), Splitter.SplitByNothing(), null, null, ExtraValues.Error),
    #"Added Custom" = Table.AddColumn(Datecolumns, "Custom", each Value.Type(#date(2023,1,1))),
    datatypelist = List.Zip({#"Added Custom"[Column1],#"Added Custom"[Custom]}),
    Result = Table.TransformColumnTypes(#"Pivoted Column",datatypelist),
    #"Datediff 1" = Table.AddColumn(Result, "Date Diff 1", each Duration.Days([date 1] - [date 2]), Int64.Type),
    #"Datediff 2" = Table.AddColumn(#"Datediff 1", "Date Diff 2", each Duration.Days([date 2] - [date 3]), Int64.Type)
in
    #"Datediff 2"

Hope this helps.

Untitled.png


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

Hi Ashish, Thank you for this solution. I have a question;

 

Would this be possible to do in DAX and not in power Query? 

 

If not, thank you.

Hi,

Here's a start.  You may download my PBI file from here.

Hope this helps.

Untitled.png


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

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.