Calculated columns: Select which columns affect calculation - powerbi

I have the following table:
SUM1 and SUM2 are calculated columns.
Org | A1 | B1 | C1 | SUM1 | A2 | B2 | C2 | SUM2 |
----|----|----|----|------|----|----|----|------|
x | 1 | 2 | 6 | 9 | 3 | 3 | 9 | 15 |
y | 2 | 3 | 5 | 10 | 4 | 5 | 3 | 12 |
z | 3 | 4 | 7 | 14 | 2 | 1 | 5 | 8 |
I would like to have a scatter plot, representing: SUM1 on X-axis and SUM 2 on Y-axis. I want one dot for each Org.
Also, I would like to filter which of A1, B1 or C1 is involved in SUM1 calculation. The same regarding A2, B2 or C2 and SUM2.
The effect I want to get is to visualize how each of these variables affects the total calculation plot when I take them out.
Is this possible at all? Is there another suggested approach?
Any comments will be much appreciated.
Thanks.

Given that you "would like to filter which of A1, B1 or C1 is involved in SUM1 calculation", SUM1 and SUM2 cannot be calculated columns. For calculations dynamically responsive to filters/slicers, you need to write measures.

I could solve the issue by doing the following: 1. Unpivoting the original table 2. Calculating a measure for SUM1 and another for SUM2. Each of them, filtering the corresponding values from the attribute column. 3. Plotting the measures one on each axis and placing Org in "Legend" in order to have a dot for each Org. 4. With a slicer "Attribute SUM1" I can filter the values of the column "Attribute" of the unpivoted table (i.e the columns of the original table) that affect the measure SUM. Then I the same for SUM2

Related

What is the more efficient way to find row-wise sum in power bi DAX?

I have a sample table with the following values:
location | col1 | col2 | col3 | col4
------------------------------------------
usa1 | 1 | 1 | 1 | 1
usa2 | 1 | 0 | 1 | 1
values are boolean for true (1) and false (0).
I would like to add a new column that shows the sum per row. from https://www.c-sharpcorner.com/article/sum-multiple-column-using-dax-in-power-bi/
it suggested the following approach:
Measure Total = SUM(table[col1]) + SUM(table[col2]) + ... + SUM(table[colx])
I am getting the expected sum for the four columns I tried. But if I have 20 columns, I was hoping you can guide me to write the DAX more efficiently.
expected output
location | col1 | col2 | col3 | col4 | sum
------------------------------------------
usa1 | 1 | 1 | 1 | 1 | 4
usa2 | 1 | 0 | 1 | 1 | 3
I would use unpivoting feature of PowerQuery to go from wide to long by selecting location and unpivot all other columns.
Then the sum by location would be immediate in any visual, no need for DAX.
One way I do it is
Sum = table[col1] + table[col2] + table[col3] + ...
I am not sure if there is another way for your situation since I only had at most 5 columns to add.

Conditional formatting on particular columns in Tableau

I have a sample dataset on which I want to perform conditional formatting. In the given sample of data, if values in column Item3>=Item1 then the corresponding records in Item3 should be highlighted in green else in red. Similarly, if values in column Item4>=Item2 then the corresponding records in Item4 should be highlighted in green else in red.
| Group | Item1 | Item2 | Item3 | Item4 |
|-------|-------|-------|-------|-------|
| A | 3 | 1 | 1 | 1 |
| B | 4 | 3 | 4 | 3 |
| C | 5 | 6 | 2 | 8 |
| D | 9 | 4 | 10 | 6 |
| E | 6 | 9 | 7 | 7 |
| F | 4 | 5 | 5 | 7 |
| G | 7 | 5 | 9 | 6 |
In the above example, rows 1 and 3 under Item3 column should be highlighted in red and rest of them in green while row 5 under Item4 column should be highlighted in red and rest in green.
I have tried creating a calculated field using if-else statement, but it highlights all the values. How can I achieve it for highlighting the cells in columns 'Item3' and 'Item4'?
One way to achieve this Viz is to have 3 sheets. First sheet is group, item1, and item 2. Second sheet is group and item3. Third Sheet is group and item4.
Create two calculated fields "3>1" and "4>2" and assign these as colors to second and third sheet respectively. Then make a dashboard with all three sheets floating, overlapping, adjusting which one is in front. I punted on titles.
Here's my result.
And here: https://public.tableau.com/app/profile/wade.schuette/viz/color-columns/Dashboard1?publish=yes

How to sum up a measure based on different levels in Power BI using DAX

I have the following table structure:
| Name 1 | Name 2 | Month | Count 1 | Count 2 | SumCount |
|--------|--------|--------|---------|---------|----------|
| A | E | 1 | 5 | 3 | 8 |
| A | E | 2 | 1 | 6 | 7 |
| A | F | 3 | 3 | 4 | 7 |
Now I calculate the following with a DAX measure.
Measure = (sum(Table[Count 2] - sum(Table[Count 1])) * sum(Table[SumCount])
I can't use a column because then the formula is applied before excluding a layer (eg. month). Added to my table structure and excluded month it would look like that:
| Name 1 | Name 2 | Count 1 | Count 2 | SumCount | Measure |
|--------|--------|---------|---------|----------|---------|
| A | E | 6 | 9 | 15 | 45 |
| A | F | 3 | 4 | 7 | 7 |
I added a table to the view which only displays Name 1in which case the measure of course will sum up Count 1, Count 2 and SumCount and applies the measure which leads to the following result:
| Name 1 | Measure |
|--------|---------|
| A | 88 |
But the desired result should be
| Name 1 | Measure |
|--------|---------|
| A | 52 |
which is the sum of Measure.
So basically I want to have the calculation on my base level Measure = (sum(Table[Count 1] - sum(Table[Count 2])) * sum(Table[SumCount]) but when drilling up and grouping those names it should only perform a sum.
An iterator function like SUMX is what you want here since you are trying to sum row by row rather than aggregating first.
Measure = SUMX ( Table, ( Table[Count 2] - Table[Count 1] ) * Table[SumCount] )
Any filters you have will be applied to the first argument, Table, and it will only sum the corresponding rows.
Edit:
If I'm understanding correctly, you want to aggregate over Month before taking the difference and product. One way to do this is by summarizing (excluding Month) before using SUMX like this:
Measure =
VAR Summary =
SUMMARIZE (
Table,
Table[Name 1],
Table[Name 2],
"Count1Sum", SUM ( Table[Count 1] ),
"Count2Sum", SUM ( Table[Count 2] ),
"SumCountSum", SUM ( Table[SumCount] )
)
RETURN
SUMX ( Summary, ( [Count2Sum] - [Count1Sum] ) * [SumCountSum] )
You don't want measure in this case, rather you need new column,
Same formula but new column will give your desired result.
Column = ('Table (2)'[Count1]-'Table (2)'[Count2])*'Table (2)'[SumCount]

How to find a cell based on row and col criteria?

I have a table like this:
| a | b | c |
x | 1 | 8 | 6 |
y | 5 | 4 | 2 |
z | 7 | 3 | 5 |
What I want to do is finding a value based on the row and col titles, so for example if I have c&y, then it should return 2. What function(s) should I use to do this in OpenOffice Calc?
later:
I tried =INDEX(B38:K67;MATCH('c';B37:K37;0);MATCH('y';A38:A67;0)), but it writes invalid argument.
It turned out I wrote the arguments of INDEX in the wrong order. The =INDEX(B38:K67;MATCH('y';A38:A67;0);MATCH('c';B37:K37;0)) formula works properly. The second argument is the row number and not the col number.

PowerBI - Comparing two similar sets of data (Many to Many)

I am trying to compare to sets of data that are very similar. I have done a bridge relation and used M:M relationship on PowerBI but I am still not getting the result I want.
Here is an example of the data:
Dataset 1
Name | Service | Usage
A | 1 | 10
A | 2 | 20
B | 1 | 10
B | 2 | 10
C | 1 | 20
C | 2 | 10
Dataset 2
Name | Service | Usage
A | 1 | 40
A | 2 | 20
B | 1 | 40
B | 2 | 10
C | 1 | 40
C | 2 | 10
Desired output
Name | Service | Usage 1 | Usage 2
A | 1 | 10 | 40
A | 2 | 20 | 20
B | 1 | 10 | 40
B | 2 | 10 | 10
C | 1 | 20 | 40
C | 2 | 10 | 10
Is this possible in PowerBI?
One approach (as suggested in comments), is to separate the distinct Name and Service values into separate dimension tables, in the query editor:
Names:
= Table.FromList(List.Distinct(List.Combine({#"Dataset 1"[Name], #"Dataset 2"[Name]})),Splitter.SplitByNothing(),{"Name"})
Services:
= Table.FromList(List.Distinct(List.Combine({#"Dataset 1"[Service], #"Dataset 2"[Service]})),Splitter.SplitByNothing(),{"Service"})
Create the DAX measures you want:
Usage 1 = SUM ( 'Dataset 1'[Usage] )
Usage 2 = SUM ( 'Dataset 2'[Usage] )
Now create relationships between the fact tables (Dataset 1, Dataset 2) and the dimension tables (Names, Services):
Then simply layout the visual as required:
Another approach may be to combine your dataset fact tables into one table, with an added "dataset" column:
Create your "combined" table in the query editor.
Combined Table:
= Table.Combine({Table.AddColumn(#"Dataset 1", "Dataset", each "Dataset 1", type text), Table.AddColumn(#"Dataset 2", "Dataset", each "Dataset 2", type text)})
Now use this table as your single source - either with a crosstab visual:
Or by adding separate measure for each dataset:
Usage 1 = CALCULATE ( SUM('Combined Data'[Usage]), 'Combined Data'[Dataset] = "Dataset 1" )
Usage 2 = CALCULATE ( SUM('Combined Data'[Usage]), 'Combined Data'[Dataset] = "Dataset 2" )