DAX measure with interim table doesn't work as expected - powerbi

I have a problem with a DAX measure in Power BI which doesn't work as expected. I would like to calculate the NSV Volume Effect based on the deviation between last and current year sales (pre-calculated measure [SalesSBA vs PY abs]) multiplied with the NSV per Unit of last year (values can be found in the linked matrix below).
The code is as following (the filter in the formula limits the calculation to pieces):
NSV Volume Effect =
VAR InterimTable =
ADDCOLUMNS(
SUMMARIZE(
FACT_SalesSBA,
DIM_Product[Product],
DIM_Date[Date],
DIM_PlanningGroup[Planning Group]
),
"NSV Volume Effect Single", CALCULATE(FACT_SalesSBA[SalesSBA vs PY abs],FILTER(ALL(DIM_SalesFacts),DIM_SalesFacts[Sales Facts]=130))*FACT_SalesSBA[SalesSBA NSV per Unit PY]
)
RETURN
SUMX(
InterimTable,
[NSV Volume Effect Single]
)
I've included the interim result of the measure ([NSV Volume Effect Single]) for debugging as a seperate measure in the matrix (link below). At that point, everything is just fine. But as soon, as the SUMX comes into account, the measure looses all those results, where we have only prior year NSV and no current one.
Unfortunately, I'm not allowed to paste images inside hte post yet, so please have a look at the Power BI matrix with all columns under this link: https://i.stack.imgur.com/INnnj.png
Any help is appreciated!
Many thanks
Axel

Related

Rolling total not calculating properly in PowerBI?

I am trying to put together a rolling monthly total measure in PowerBI but my measure is not even calculating
My data is similar to below
My data
Data Model
I have made my calculation as follows:-
Rolling Annualized Revenue =
CALCULATE(
[Annual Revenue],
FILTER('Calendar Lookup',
'Calendar Lookup'[Date]
<=MAX('Calendar Lookup'[Date])))
Edit: I just realized I copied the wrong formula altogether here
For whatever this is not working at all and yields just the annual revenue not a rolling sum
Calc Result in a matrix
I determined that I needed to add the year to the row context in order for my calculation to work properly.

DAX: How to use TOTALYTD measure on date-filtered visual?

I have the following two measures:
Number of Contracts = COUNTROWS(Contracts)
Number of Contracts YTD = TOTALYTD([Number of Contracts];Calendar[Date])
The second measure works fine in most of my visuals, however I am having problems with a date-filtered matrix.
In the matrix I am filtering the visual by yesterday's month&day and I am showing the Number of Contracts YTD year by year (by placing Year in the matrix Rows).
When I do so, there is no difference between Number of Contracts YTD and Number of Contracts.
I tried nesting Calendar[Date] inside ALL, but it's not working (2020's data doesn't change, while earlier data disappears).
How can I handle it? Thanks

Power BI YTD Calculations

I am trying to do some time based calculations on my budgeting data but struggling to understand where I'm going wrong or if my data structure would even support what I'm trying to do.
As per the image above, this is my raw data. ie. A monthly budgeted and actual total for each cost centre that is being imported from an excel spreadsheet.
I am trying to calculate a YTD budget and YTD Actual figure per cost centre based on the monthly totals. Ideally I would like all of this data displayed in a table that I can then use slicers to segment/pivot.
When using the CALCULATE() function in a measure, I am unable to select my cell value for each date and cost centre.
eg.
YTD Actual = CALCULATE( [Actual MTH] , DATESYTD('Dates'[Date], "30/6"))
returns the error
The value for 'Actual MTH' cannot be determined. Either 'Actual MTH'
doesn't exist, or there is no current row for a column named 'Actual
MTH'.
Any assistance with getting a greater understanding of the issue here would be appreciated.
Thanks
Try something like this for your measures:
YTD Actual = TOTALYTD(sum([Actual MTH]),'Dates'[date],ALL('Dates'[date]),"30/6")

Pareto Chart with a Percentage Measure Power BI

I'm having an issue with a dashboard that I'm creating.
I need to make a Pareto Chart and I found a lot of tutorials on the Internet of how to make it in Power BI, however, I need to use a measure that is a percentage and this is where I'm stuck.
Here's a part of my table:
I made a measure that is a percentage of Não_Recebido_Dinâmico by Fat_Liq1. The measure is:
% Inadimplência_Dinâmico = DIVIDE(SUM('Mapa_de_Faturamento (2)'[Não_Recebido_Dinâmico]);
SUM('Mapa_de_Faturamento (2)'[Fat_Liq.1])) + 0
So I need to make a Pareto Chart with the top 10 Cursos by this measure. When I apply the ways of the Pareto Chart on the Internet it doesn't work because they use the total of the measure to make the accumulated percentage.
For example, these are the top 10 Cursos by the measure % Inadimplência_Dinâmico. I think that to make the Pareto Chart works properly, the total and the accumulated should be the sum of the measure, but that's not what happens in Power BI because it keeps considering it as a percentage.
I've tried to make the same measure as a calculated column but it doesn't work either, because in this case, it sums up the percentage of all rows.
I'm not familiar with the DAX functions of Power BI, so I need some help.
This is what I want in Power BI, but made in Excel:
Thank you all!
First, let's create a calculated column for the ranking (names abbreviated for legibility):
Ranking = RANKX(
SUMMARIZE('Mapa_'; 'Mapa_'[Curso]);
CALCULATE(
DIVIDE(SUM('Mapa_'[Não_]); SUM('Mapa_'[Fat_]));
ALL('Mapa_');
'Mapa_'[Curso] = EARLIER('Mapa_'[Curso])))
Now we can create a cumulative measure:
Accum = DIVIDE(
CALCULATE(
SUM('Mapa_'[Não_]);
FILTER(ALLSELECTED('Mapa_');
'Mapa_'[Ranking] <= MAX('Mapa_'[Ranking])));
SUM('Mapa_'[Fat_]))
Now you can create a Line and Bar Chart with Curso on the shared axis, % Inadimplência_Dinâmico on the column values, and Accum on the line values.
Note that this will have all of the cursos until you apply appropriate filtering. To do this, go to the visual level filters (or page level or report level) and choose Top N filtering for Curso. You want to show the Bottom 10 item using the Ranking column as for the By value choice.
The ALLSELECTED part of the Accum measure will make sure you're only including the top 10 that you want and not all of the rows.

DAX measure - show values from best day

I have, in PowerBI (October 2017 release) some data showing the snapshotted output of some solar panels at five-minute intervals.
I presently have a measure which calculates the total production for each day by getting a sum of the instantaneous readings for the day and dividing by 12 (because there are 12 readings per hour) and then shows the average of this daily amount over whichever period is in the current context:
Avg Daily Production (KWh) =
AVERAGEX(SUMMARIZE('Solar Output', 'Solar Output'[Date], "Daily Production (KWh)", SUM('Solar Output'[Production (KW)]/12), [Daily Production (KWh)])
For my visualisations I'd like to show a chart which displays the average production at various times of the day compared to the production at that time for the best day, i.e. the day with the highest value for [Avg Daily Production (KWh)].
Here is my working so far:
Identify the top day by using
Best Day = TOPN(1, SUMMARIZE('Solar Output', 'Solar Output'[Date], "Daily Production (KWh)", [Avg Daily Production (KWh)]), [Daily Production (KWh)], DESC)
But this produces a row, not a scalar, and I can't quite work out how to just get this date and use it as a filter for a measure like this:
Production On Best Day (KW) =
CALCULATE(SUM([Production (KW)]), FILTER(ALL('Solar Output'[Date]), 'Solar Output'[Date] = [Best Day]))
The chart I want would look like this, with the average production for the selected dates in green and then another series showing the production at those times on the best day pencilled in red.
Can't really get my head around the calculations involved but I hope I get your requirement.
So you want to plot two lines on the same chart, one always being the data from the best day as reference, and the other one the data selected from the date filter, right?
You're actually pretty closed to the solution with the info given above.
I just modified your DAX to:
Production On Best Day (KW) =
CALCULATE(
SUM('Solar Output'[Average]),
FILTER(
ALL('Solar Output'[Date]),
'Solar Output'[Date] = VALUES('Best Day'[Date])
)
)
(Not quite sure how you compute your intermediate measures so you may need to adjust according to your measures)
Yes, TOPN() returns a table, so you can get the date value using VALUES('Best Day'[Date]) and use it for comparison.
Results:
Alternate approach to solve this issue is to use the MAXX() function to get a scalar value out of the the table returned by TOPN().
This works where MAX() doesn't because MAXX() accepts a table expression as its first argument (the table expression is the result of the TOPN() function) where MAX() only takes columns from existing tables.
Best Day = MAXX(TOPN(1,
SUMMARIZE(ALL('Solar Output'),
'Solar Output'[Date],
"Daily Production (KWh)",
[Avg Daily Production (KWh)]),
[Daily Production (KWh)],
DESC),
[Date])
The benefit of this approach is that it should work in versions of DAX with no calculated table support (e.g. SSAS 2014, Excel 2013).