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
Khostri
New Member

Join tables to create matrix like view od data map

Hi all,

i am pretty new to Power Query. I just need to simulate similar result as with Excel (but Excel solution is really slow).

 

I have one big table, already cleaned, polished in Power Query, looking like that (with other columns):

 SourceList

nameproductOther columns with data
pc1SQL 2014data
PC1Office 2013data
PC1.NETdata
PC1ESETdata
PC1Exchange 2013data
PC1Acrobatdata
pc2SQL 2016data
PC2.NETdata
PC2ESETdata
PC2Office 2016data
PC2Acrobatdata
PC3Office 2010data

 

Next I have table with list of programs to monitor: (sorted by group descending and secondly name descending)

 Monitored

namegroup
SQL 2016200
SQL 2014200
SQL 2012200
Office 2016180
Office 2013180
Office 2010180
Exchange 2016160
Exchange 2013160
Exchange 2010160

 

This table doesn't have fixed number of rows, it can dynamically change.

 

I need to combine two tables to looks like that:

Result

nameOther Columns with DataSQL 2016SQL 2014SQL 2012Office 2016Office 2013Office 2010Exchange 2016Exchange 2013Exchange 2010
pc1data010010010
PC2data100100000
PC3data000001000

 

So name is deduplicated, rows from Monitored are transposed to columns in Result (number of transposed columns is dynamic, for example from 5 to 300 columns based on Monitored) and in each column there is a value "1" if Product in current column exist on curent PC name (and if not, then 0 or null)

 

I cannot figure how to do it. I am able to do it in Excel by pure formulas (without VBA), but not sure in Power Query. I have tried to check values against columns names, but don't know how to handle dynamic number of columns.

In Excel in looks like that (Result table formula in each cell):

 

=ABS(COUNTIFS(Installation!$F:$F;map!$A5;Installation!$I:$I;map!M$1)>0)

 

Count number of values where Name from current row is found in table Source list and value in Product column equals current Column header.

 

For easier understanding there I try to change formula to presented tables in this post:

So for column SQL 2016 it would looks like:

 

=ABS(COUNTIFS(SourceList[[#Data];[Name]];Result[@[Name]];SourceList[[#Data];[Product];Result[[#Headers];[SQL 2016]])>0)

 

But the header name "SQL 2016"  in Excel change for each additional column (its filled in Sheet so formula just takes first row value for comparsion and it doesnt matter how many columns are there). I am using countifs as source for boolean comparsion and then only true or false is result in Excel converted to numeric

 

After I will be able to figure first step, I will need the second one:

Create new table based on result, but each value would be calculated diffrently based on group value from table Monitored and Other data.

 

So :

Adjusted

nameSQL 2016SQL 2014SQL 2012Office 2016Office 2013Office 2010Exchange 2016Exchange 2013Exchange 2010
pc1CalcGroup200CalcGroup200CalcGroup200CalcGroup180CalcGroup180CalcGroup180CalcGroup160CalcGroup160CalcGroup160
PC2CalcGroup200CalcGroup200CalcGroup200CalcGroup180CalcGroup180CalcGroup180CalcGroup160CalcGroup160CalcGroup160
PC3CalcGroup200CalcGroup200CalcGroup200CalcGroup180CalcGroup180CalcGroup180CalcGroup160CalcGroup160CalcGroup160

 

And in each group calculation is from rightmost column of each group to the leftmost group column - so for example SQL:

  1. SQL 2012 Calculation is used, based on data from Result (if value in Result is 1, then calculate value Adjusted based on Other data)
  2. Then SQL 2014 - if value is 1, then calculation based on Other data and computed result SQL 2016 in Adjusted

Please anyone can help me with this problem or have examples how to do it?

 

I just started to think for example about using map as bits - so for each value in Monitored add bit value, probably descending (number of rows is max exponent, then each value has number like 1,2,4,8,16,32 but in descending order). Then map can be created by adding joined value to table, sum it, then convert to binary, add leading characters and separate binary to each column. But not sure how to realize it in Power Query. Is it right idea?

 

Thank you anyone for help

1 ACCEPTED SOLUTION
v-huizhn-msft
Employee
Employee

Hi @Khostri,

I type the two tables in Power BI, and create a relationship between them as follows.

1.PNG

Then I create a measure using the formula.

Measure = COUNTA(T1[product])+0

Create a matrix visual, select the T1[name] as rows, the T2[name] as columns, you will get expected result.

2.PNG

Best Regards,
Angelia

View solution in original post

1 REPLY 1
v-huizhn-msft
Employee
Employee

Hi @Khostri,

I type the two tables in Power BI, and create a relationship between them as follows.

1.PNG

Then I create a measure using the formula.

Measure = COUNTA(T1[product])+0

Create a matrix visual, select the T1[name] as rows, the T2[name] as columns, you will get expected result.

2.PNG

Best Regards,
Angelia

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.