Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM. Register now.

Reply
TopHat
Frequent Visitor

List string values in a matrix depending on different permutation

Hi all

 

Screenshot of the sample source data:

TopHat_1-1646069052910.png

Sanitised sample data in usable format:

UserIDDayDiscountedHandsetFreeTrariffPhoneHasOrderedQuantitySale
11YYSamsungN00
21YNAppleN24566
31NNSamsungN00

 

 

I have a matrix made as below

 

Screenshot:

TopHat_0-1645177703442.png

Sanitised sample data in usable format:

UserID12345
1SamsungSamsung NokiaNokiaSamsung
2AppleApplePixel PixelSamsung
3SamsungPixelNokia AppleNokia
4NokiaNokiaPixel PixelSamsung
5PixelAppleApple PixelApple
6SamsungPixelApple SamsungNokia
7AppleNokiaApple ApplePixel
8NokiaApplePixel NokiaNokia
9SamsungAppleApple AppleNokia
10PixelAppleSamsung AppleApple

 

 

The Days are across and Rows have UserID and Values are names of Phones:

TopHat_0-1645178971669.png

 

 

I need a second table that displays the list of times a phone changed from one day to the next day by each user.

Additionally also need the number of times users have made each kind of change.

The comparison is only against the previous day.

 

 

The output I am after is (please note the table below is not complete):

 

Screenshot:

TopHat_0-1645539994719.png

 

 

Sanitised sample data in usable format:

FromChanged ToIn DayHow many users
SamsungNokia31
NokiaSamsung51
ApplePixel32
PixelSamsung52
SamsungPixel22
NokiaApple41
AppleNokia52
NokiaPixel31

 

The model looks like the below:

TopHat_4-1645177938563.png

 

You can find the file in the link below:

Like to pbi file 

 

 

Many thanks in advace.

 

 

 

13 REPLIES 13
Greg_Deckler
Community Champion
Community Champion

@TopHat I fail to understand your numbers. For the first row in your table you have Samsung to Nokia day 3 and you have 3 users but only one switched on day 3 from Samsung to Nokia. So...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Apologies I have left the "How many users" column with dummy data but I have now correct it and it now contains real output data.

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to work with. Please show the expected outcome based on the sample data you provided.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

Hi @lbendlin , The output that I have posted is the actual output. 

It is not a set of complete rows as there will be more combinations int the fileds "From" and "Changed to" but the first 8 rows contain actual permutations and is the right out come.

 

Please provide sanitized sample data in usable format. A screenshot is not a usable format.


I see what you mean. 

I have updated the output now hope that's better.

Nearly there. Now please do the same for the source data.

Okay done that too now 😊

See attached for one possible solution.  Note that your data model is (mostly) accurate but rather useless for the question you are trying to answer. Instead you need to use tons of disconnected tables and crossjoins.  Might get away with using TREATAS or CROSSJOIN(,,none) - which might be necessary if you want this to scale for larger date ranges.

 

 

Slightly "optimized"  version stuffing everything into a single calculated table.

 

1. source data "Facts" 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUQpOzC0uzUtHsBSATL/87MxEJBqmKFYnWskIyHcsKMhJRaIDMitScxRgDDQNxii2wFSAjVZAMgNiF0iDCRYX4LXBFEkcxWkKGBIg5WZYHQTXgJBCOMkcw6FIGlBCAazcAl0Zsg9QvQZSboliK4YPMEPI0ACLj5HiDzV+YmMB", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [UserID = _t, #"1" = _t, #"2" = _t, #"3" = _t, #"4" = _t, #"5" = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"UserID"}, "Attribute", "Value"),
    #"Renamed Columns" = Table.RenameColumns(#"Unpivoted Other Columns",{{"Attribute", "Day"}, {"Value", "Phone"}})
in
    #"Renamed Columns"

2. Calculated Table "Summary"

Summary = FILTER(CROSSJOIN(DISTINCT(SELECTCOLUMNS(Facts,"From Phone",Facts[Phone])),DISTINCT(SELECTCOLUMNS(Facts,"To Phone",Facts[Phone])),VALUES(Facts[Day])),[From Phone]<>[To Phone] && Facts[Day]>1)

3. adding calculated column:

Users = 
var d=Summary[Day]
var f=Summary[From Phone]
var t=Summary[To Phone]
var u=SELECTCOLUMNS(CALCULATETABLE(Facts,Facts[Phone]=t,Facts[Day]=d),"User",Facts[UserID])
var p=SELECTCOLUMNS(CALCULATETABLE(Facts,Facts[Phone]=f,Facts[Day]=d-1),"User",Facts[UserID])
return COUNTROWS(intersect(u,p))

Result:

lbendlin_0-1645552054288.png

 

 

 

Thanks for taking the time to look into this but you have used the result of the first matrix as the source data rather than what is in the file. 

 

Also, would you mind sharing the file for the slightly optimised one as well please. 

see attached

Thanks @lbendlin.

 

I have also added what the source looks like. 

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.