PowerBI Desktop - SUM Ignoring Filters - powerbi

My visual has a simple data table which has a number of rows, each representing an invoice. Each invoice has a number of items, including the sales rep, creation date, and the amount.
I have a number of slicers including sales rep, date of creation, etc.
I'm trying to add a column which, for each row, shows the percentage that that particular invoice is of the shown invoices. So, for example, when I use a filter to only show a subset of all rows, I want each row to show a percentage of the total of that subset, not the percentage of all rows.
Imagine this table:
|ID|Rep |Value|Percentage|
| 1|Dave| 10| 50|
| 2|Sue | 3| 15|
| 3|Dave| 5| 25|
| 4|Sue | 2| 10|
The Percentage column is created by Value/SUM(Value) and is showing correctly above. The SUM(Value) is 20; Dave's 10 is 50% of that, Sue's 3 is 15% of it, and so forth.
I have a slicer for Rep. So if I choose 'Dave' in that slicer, the table looks like this:
|ID|Rep |Value|Percentage|
| 1|Dave| 10| 50|
| 3|Dave| 5| 25|
The Percentage column is being created based on the SUM(Value) of ALL rows (i.e. 20) not just the ones that are showing because of my slicer (i.e. 15). I would have expected the percentages to be 66.67% and 33.33%, being the percentages of the total of what's showing. Why isn't it? And how do I get it to be?

It looks like your percentage column is a calculated column rather than a measure. Calculated columns cannot be responsive to slicers as they are calculated only once per data load.
Try creating Percentage as a measure instead:
Percentage = SUM(Table1[Value]) / CALCULATE( SUM(Table1[Value]), ALLSELECTED(Table1) )

Related

Extract values from column to use in calculated measure formula

I have TABLE A
In that table I have a measure with values like so:
Targets|
--------
4 |
5 |
6 |
In the same table I have a calculated column (summed totals) like so:
Totals |
--------
10 |
11 |
12 |
Because this is a direct query data source, query editor is disabled and manipulation must be done through DAX formulas.
I would like to do a simple operation of Targets-Totals
Code I've tried for a calculated column:
test = TableA[targets] - TableA[totals]
However this results in an error:
The column TableA[test] cannot be pushed to the remote data source and cannot be used in this scenario.
How can I create a new column with the above operation considering the fact that one column is a 'measure ' and the other a 'calculated column'
In this case, you will need a measure that does a row by row calculation, but not as a calculated column. For this you will need SUMX which will do a iteration.
Your measure should be:
New Measure = SUMX(TableA, [targets] - [totals])

PowerBI DAX - Filter Total based on selected columns

I have the table that looks like this:
Column Header: User | Test Score 1 | Test Score 2 | Test Score 3 | Total Points | Status
Row: Person1 | 50 | 70 | 75 | 195 | Failed
Row: Person2 | 70 | 75 | 85 | 210 | Passed
The "Total Points" column is simply the SUM of the three test scores and the "Status" is calculated based on the "Total Points" (if "Total Points" < 200, "Failed", "Passed").
What I'm having difficulty with is that sometimes a test needs to be eliminated from the equation. I would like the end user to be able to uncheck a box in the filters area or on a slicer to remove a test from the equation for the "Total Points", which would then affect the "Status". Since the test is a column header and not a value, I can't seem to find a way to make this work.
The data table is already in a report layout. That makes your intention difficult to process. A better layout would be a flat table in this format:
Name, Test number, Score
You can use Power Query to unpivot the data to get from your layout to the flat table. With a flat table, you can then build a measure for the total and add a slicer to the report where the test number can be selected.
Build a matrix visual with the Name in the rows and the test number in the columns, the measure for the total in the values. Then use the slicer to remove tests from the matrix at your discretion.

How to calculate Annual Variance on Monthly basis?

Am new to Power BI and appreciate help on DAX for this requirement:
I have a FY slicer (July-June) in my Power BI reports and wants to show monthly trending across different FY years. Target data is structured like this in a table:
Dates | Target
30-06-2018 | 34000
30-07-2018 | 34000
30-08-2018 | 34000
********** | *****
30-06-2019 | 30000
30-07-2019 | 30000
********** | ******
I need to calculate annual variance with below formula to get monthly baseline for next year(2019), then calculate cumulative reduction variance across July-June:
('Target of 30-06-2018') - ('Target of 30-06-2019')/ 12
Dates are linked to another DATE table, which has Financial year and Financial month columns.
Thanks so much in advance for the help!!
Anita
You need to use the DAX PARALLELPERIOD
PARALLELPERIOD(<dates>,<number_of_intervals>,<interval>)
The documentation gives a perfect example:
= CALCULATE(SUM(InternetSales_USD[SalesAmount_USD]), PARALLELPERIOD(DateTime[DateKey],-1,year))
So your calculation will something like:
= (
CALCULATE(SUM(TargetTable[Target])) -
CALCULATE(SUM(TargetTable[Target]), PARALLELPERIOD(Dates[Date],-1,year))
) / 12
If you want monthly variance, then you need to ensure that Dates[Date] is filtered at a grain to return a table of dates for the entire target month.
You can find a great blog on it here
For next year, I got June Baseline value with SAMPLEPERIODLASTYEAR.
1: Last year value = CALCULATE(SELECTEDVALUE (TargetTable[Target]),
SAMPLEPERIODLASTYEAR (Dates[Date]))
2: Base Target = IF (MONTH(SELECTEDVALUE(TargetTable[Dates])=6, DIVIDE ([Last year value]-SELECTEDVALUE (TargetTable[Target]), 12))
Still need to figure out Cumulative monthly variance across next financial year?

Split data into categories in the same row in Power BI

I have a table that contains multiple columns with their named having either the suffix _EXPECTED or _ACTUAL. For example, I'm looking at my sold items from my SoldItems Table and I have the following columns: APPLES_EXPECTED, BANANAS_EXPECTED, KIWIS_EXPECTED, APPLES_ACTUAL, BANANAS_ACTUAL, KIWIS_ACTUAL (The Identifier of the table is the date, so we have results per date). I want to show that data in a table form, something like this (for a selected date in filters:
+------------+----------+--------+
| Sold items | Expected | Actual |
+------------+----------+--------+
| Apples | 10 | 15 |
| Bananas | 8 | 5 |
| Kiwis | 2 | 1 |
+------------+----------+--------+
How can I manage something like this in Power BI ? I tried playing with the matrix/table visualization, however, I can't figure out a way to merge all the expected and actual columns together.
It looks like the easiest option for you would be to mould the data a bit differently using Power query. You can UNPIVOT your data so that all the expected and actual values become rows instead of columns. For example take the following sample:
Date Apples_Expected Apples_Actual
1/1/2019 1 2
Once you unpivot this it will become:
Date Fruit Count
1/1/2019 Apples_Expected 1
1/1/2019 Apples_Actual 2
Once you unpivot, it should be fairly straightforward to get the view you are looking for. The following link should walk you through the steps to unpivot:
https://support.office.com/en-us/article/unpivot-columns-power-query-0f7bad4b-9ea1-49c1-9d95-f588221c7098
Hope this helps.

Slicer for Merged, Multi-Column Rows

I have two (2) tables: Invoices and Products. They look like this:
**Invoices**
InvoiceID
SalesRep
**Products**
InvoiceID
ProductID
Cost
ProductName
The Invoices.InvoiceID column is unique. Any invoice may have 1-n products attached to it. In the Products table, there can be any number of duplicate InvoiceIDs, each showing one ProductID (and its cost) that appeared on that Invoice.
Our business sells licenses to use our products (not the products themselves; just licenses). Those licenses can be renewed yearly. So in our DB, our products have names like 'Product A' and 'Product A (Renewal)'. The '(Renewal)' bit indicates that this product is actually a renewal of Product A, not the first purchase of the license. Apart from that, they are identical.
We need to split our invoices and their products by Renewals and non-renewals (we call it New). In the output table, we want just one row for each invoice, no matter how many products it has. It'll look like this:
|Invoice ID|Sales Rep|Total Cost|Renewal Products |Renewal Cost|New Products |New Cost|
|001 |F. Smith | $100|Product A (Renewal)| $100 | | |
|002 |J. Blow | $250|Product B (Renewal)| $150 |Product A | $100|
|003 |B. Bloggs| $300| | |Product C & Product D| $300|
And so on. Note that where there are multiple products of either New or Renewal, they are concatenated. I achieved that by the DAX:
New Products = CONCATENATEX (filter(Products,
Products[InvoiceID]=min(Invoices[InvoiceID]) && iserror(SEARCH("renewal",
Products[ProductName]))),
Products[ProductName],
" & " ,
Products[ProductName],
ASC)
and I did a similar one for the Renewal products. The costs, too, add together, so that if there are multiple products of either New or Renewal, their costs add together, like for invoice 003 in the table above. Again, DAX:
New Total = SUMX(FILTER(Products,
Products[Invoice ID]=min(Invoices[InvoiceID]) && iserror(SEARCH("renewal", Products[ProductName]))),
Products[Cost])
So far, so good. I have the table looking the way I want it. But the business wants to be able to slice the output table by New or Renewal. When they choose either, then it as if the other type of business doesn't even exist. The columns for that type of business in the output table will be empty, and the Total Cost column will show only the total cost of any items of the chosen type in the order. And if any invoice has only products of the type not chosen, that invoice will disappear from the output completely.
I am really struggling with this slicer, so any suggestions will be gratefully received. Thanks a lot
Edit
Alexis, if the original table looks like this:
|Invoice ID|Sales Rep|Total Cost|Renewal Products |Renewal Cost|New Products |New Cost|
|001 |F. Smith | $100|Product A (Renewal)| $100 | | |
|002 |J. Blow | $250|Product B (Renewal)| $150 |Product A | $100|
|003 |B. Bloggs| $300| | |Product C & Product D| $300|
Then after slicing to show only New, it would look like this:
|Invoice ID|Sales Rep|Total Cost|Renewal Products |Renewal Cost|New Products |New Cost|
|002 |J. Blow | $100| | |Product A | $100|
|003 |B. Bloggs| $300| | |Product C & Product D| $300|
And after slicing to show only Renewal, it would look like this:
|Invoice ID|Sales Rep|Total Cost|Renewal Products |Renewal Cost|New Products |New Cost|
|001 |F. Smith | $100|Product A (Renewal)| $100 | | |
|002 |J. Blow | $150|Product B (Renewal)| $150 | | |
Does that help?
This is actually simpler than you might expect. All you need to do is create a calculated column on the Products table that distinguishes between the new and renewal rows:
Slicer = IF(SEARCH("Renewal", Products[ProductName], 1, 0) > 0, "Renewal", "New")
Then use this column as a slicer and the table should behave as you specified.
Note: If you create this column first, then your measures can reference it rather than using the SEARCH function. I.E., you can replace
`iserror(SEARCH("renewal", Products[ProductName]))`
with
Products[Slicer] = "New"