cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
Syndicate_Admin
Administrator
Administrator

Build a compare matrix

Hi, 

 

I want to build a Matrix for this Sample Data

ModelType
Model 1

A45

Model 1

A12

Model 2

A45

Model 2

B23

Model 2

A12

Model 3

A45

Model 3

B23

Model 3

E24

 

From this Data i want to find out the absolute differences and get a Matrix like this.

 

 Model 1Model 2Model 3
Model 1012
Model 2102
Model 3220

 

Can someone help me and give me an advice how to come to the solution.

 

Thanks a lot.

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

HI @Syndicate_Admin ,

Please check the model.

DimModel;

vcgaomsft_0-1685084114334.png

relationships:

vcgaomsft_1-1685084142489.png

Absolute Difference = 
VAR _COL = CALCULATETABLE(VALUES('Table'[Type]), 'Table'[Model] = MAX('DimModel'[Model]))
VAR _ROW = CALCULATETABLE(VALUES('Table'[Type]), 'Table'[Model] = MAX('Table'[Model]))
VAR _ROW_COUNT = COUNTROWS(_ROW)
VAR _COL_COUNT = COUNTROWS(_COL)
VAR _DIFF_COUNT = COUNTROWS(INTERSECT(_COL,_ROW))
VAR _RESULT = IF(MAX('DimModel'[Model])>=MAX('Table'[Model]),ABS(_COL_COUNT-_DIFF_COUNT),ABS(_ROW_COUNT-_DIFF_COUNT))
RETURN
_RESULT

vcgaomsft_2-1685084169234.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

 

 

View solution in original post

2 REPLIES 2
v-cgao-msft
Community Support
Community Support

HI @Syndicate_Admin ,

Please check the model.

DimModel;

vcgaomsft_0-1685084114334.png

relationships:

vcgaomsft_1-1685084142489.png

Absolute Difference = 
VAR _COL = CALCULATETABLE(VALUES('Table'[Type]), 'Table'[Model] = MAX('DimModel'[Model]))
VAR _ROW = CALCULATETABLE(VALUES('Table'[Type]), 'Table'[Model] = MAX('Table'[Model]))
VAR _ROW_COUNT = COUNTROWS(_ROW)
VAR _COL_COUNT = COUNTROWS(_COL)
VAR _DIFF_COUNT = COUNTROWS(INTERSECT(_COL,_ROW))
VAR _RESULT = IF(MAX('DimModel'[Model])>=MAX('Table'[Model]),ABS(_COL_COUNT-_DIFF_COUNT),ABS(_ROW_COUNT-_DIFF_COUNT))
RETURN
_RESULT

vcgaomsft_2-1685084169234.png

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

 

 

slorin
Super User
Super User

Hi,

Try this

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8s1PSc1RMFTSUXI0MVWK1UERMTRCEjHCUAMScTIyRleDossYQ5cxhi6QiKuRiVJsLAA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Model = _t, Type = _t]),
Join = Table.NestedJoin(Source, {"Type"}, Source, {"Type"}, "Source", JoinKind.LeftOuter),
Expand = Table.ExpandTableColumn(Join, "Source", {"Model"}, {"Model.1"}),
Filter = Table.SelectRows(Expand, each [Model.1] <> [Model]),
Pivot = Table.Pivot(Filter, List.Sort(List.Distinct(Filter[Model.1])), "Model.1", "Type", List.Count)
in
Pivot

Stéphane 

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors