Calculated Table Cumulative Total - powerbi

I'm trying to add a column with a cumulative total in a calculated table with this DAX:
CALCULATE(sum('Eighty20'[LTV]), FILTER( ALLSELECTED( Eighty20 ), Eighty20[Rank Asc] <= MAX (Eighty20[Rank Asc])))
However, I'm getting the overall sum in each field rather than the cumulative total. Any ideas why?

The reason you get the total is that you filter based on :
Eighty20[Rank Asc] <= MAX (Eighty20[Rank Asc])
This returns all the rows because it checks if the current Rank Ac <= max, what is always true. To get cumulative:
yourColumn =
var curRank = Eighty20[Rank Asc]
return CALCULATE(sum('Eighty20'[LTV]), FILTER(Eighty20, Eighty20[Rank Asc] <= curRank))

Related

Cumulative total percentage in Power BI

I have a summary table in Power BI which shows how many days it takes for leads to convert to a sale. It has 2 columns, sum_convert (the amount of days in between lead creation date and converted date) and count_lead (the count of leads that have taken that amount of days to convert), both are numeric values. Here is an example of the data:
What I want, is a column next to count_lead that shows the running percentage total in the specific ascending order of sum_convert. Currently I've created a measure called lead_count which is the sum of count_lead. Then I've attempted to create the cumulative total with the following measure:
Cum_Lead = calculate([lead_count], FILTER(ALL(Convert_Count_Summary[Sum_Convert]), SUM(Convert_Count_Summary[count_lead]) <= [lead_count]))
This creates a cumulative total, but not in the specific sum_convert order, it's in the order of largest volume for count_lead. Any idea what I need to change so that it's in the order of sum_convert?
You could do this in Power Query using M:
= Table.AddColumn(#"Previous Step", "Cumulative_Count_PQ", each List.Sum(List.FirstN(#"Previous Step"[count_lead],_[sum_convert]+1)), type number)
Or as a calculated column using DAX:
Cumulative Count DAX =
CALCULATE (
SUM ( Convert_Count_Summary[count_lead] ),
ALL ( Convert_Count_Summary ),
Convert_Count_Summary[sum_convert] <= EARLIER ( Convert_Count_Summary[sum_convert] )
)
Edit:
Cumulative percentages in Power Query:
= Table.AddColumn(#"Previous Step", "Cumulative_Count_Percent_PQ", each List.Sum(List.FirstN(#"Previous Step"[count_lead],_[sum_convert]+1)) / List.Sum(#"Previous Step"[count_lead]), Percentage.Type)
Cumulative percentages calculated column in DAX:
Cumulative Count % DAX =
VAR _Numerator =
CALCULATE (
SUM ( Convert_Count_Summary[count_lead] ),
ALL ( Convert_Count_Summary ),
Convert_Count_Summary[sum_convert] <= EARLIER ( Convert_Count_Summary[sum_convert] )
)
VAR _Divisor =
SUM ( Convert_Count_Summary[count_lead] )
RETURN
DIVIDE (
_Numerator,
_Divisor
)

How to create a cumulative sum over two columns with comlementary Date Range in Power BI

I'm trying to build a line Chart to show the cumulative sum of the Forcast. I have two Tables, one for the Actuals and one for the forcast, both linked to a Date table. The Chart should show the cumulative sum of the actuals till current month and from next month on those from the Forcast.
I've created so far the following measures to get the Forcast Chart:
Chart_Forecast not cumulated =
VAR Actual_Hrs_not_cumulated = CALCULATE([Total Actuals],FILTER(IN_ACTUALS, IN_ACTUALS[Date] <= MAX(CurrentMonth[CurrentMonthParameter])))
VAR Forecast_not_cumulated = CALCULATE([Total Forecast],FILTER(IN_Forecast, IN_Forecast[Date] > MAX(CurrentMonth[CurrentMonthParameter])))
RETURN
IF((SELECTEDVALUE('LT_Reporting Calendar'[Date]) <= MAX(CurrentMonth[CurrentMonthParameter])),Actual_Hrs_not_cummulated, Forecast_not_Cumulated)
This one gives me the line chart of the non cumulated Forcast, and it works.
But as soon as I want to build the cumulative sum on the measure above according to the measure below, I get only the cumulative sum till current month and the future is omitted. I think I have a filter issue.
I've tried many methods of building a cumulative sum, always getting the same result.
Chart_Forcast Cumulated =
CALCULATE(
[Chart_Forecast not cumulated],
FILTER(
ALL('LT_Reporting Calendar'[Date]),
'LT_Reporting Calendar'[Date] <= MAX ('LT_Reporting Calendar'[Date])
)
)
Input:
Result: The Chart
Does any body have an Idea on this?
Many Thanks in advance
I'd suggest writing it as a sum like this:
Cumulative =
VAR ParameterDate = SELECTEDVALUE ( CurrentMonth[CurrentMonthParameter] )
VAR AxisDate = SELECTEDVALUE ( 'LT_Reporting Calendar'[Date] )
RETURN
CALCULATE (
[Total Actuals],
'LT_Reporting Calendar'[Date] <= AxisDate,
'LT_Reporting Calendar'[Date] <= ParameterDate
) +
CALCULATE (
[Total Forecast],
'LT_Reporting Calendar'[Date] <= AxisDate,
'LT_Reporting Calendar'[Date] > ParameterDate
)

sum product of two columns in powerbi table with dax

I would like to get the sum product of this table:
example: (0*.0256) + (1*.0468) + (2*.0344) ...
days to departure is a dimension under one table. And Conversions is a measure that I'm showing as % of Grand Total.
Thanks for any advice.
So we have table T with the column [Days To Departure] and the measure [%GT Conversions]
We want a measure to sum all the values of [%GT Conversions] for all the rows of T.
Let's call this measure [Total Formula], since I don't know what it'd be expected to represent
Total Formula =
VAR Total = SUMX( ALL( T ), T[Conversion] )
RETURN
SUMX( ALL( T ), T[Days To Departure] * T[Conversion] / Total )

DAX to calculate cumulative sum column (year to date) for all individual products

I have 3 columns in a table: Date, Product, and Volume. Based on this is I want to calculate the cumulative sum (or YTD) column for each of the products.
I know that to calculate cumulative total we use:
YTD_Actual = CALCULATE(Sum(Combined[Actual Volume]),FILTER(Combined,Combined[Date] <= EARLIER(Combined[Date])))
But I want this to additionally filter individual products and do this calculation for that product.
The expected column is shown in the picture below:
As far as you manage to get the Month column in date format, the following works:
YTD =
VAR currProduct = Table1[Product]
VAR currMonth = Table1[Month]
VAR ytdTotal =
CALCULATE(
SUM(Table1[Volume]),
FILTER(
ALL(Table1),
Table1[Month] <= currMonth &&
Table1[Product] = currProduct
)
)
RETURN IF(NOT(ISBLANK(ytdTotal)), ytdTotal,0)
Result:

How to get a value from a Range? - Power BI

I have data in a table and depending on their sale I have to assign a cost:
For example, if have a sale of 200,000 my cost will be 61,298.
I have tried to make a measure to get this but with my current formula, I only get the Sum of all of the values of Cost.
Cost of Sale = CALCULATE(SUM('Cat_VEA0 Cost'[Cost]),
FILTER('Cat_VEA0 Cost',
[Sales] >= MIN('Cat_VEA0 Cost'[From]) &&
[Sales] < MAX('Cat_VEA0 Cost'[To])))
So I don't know, how to get the value of Cost, depending on which range of Sales it is each shop.
You can use MAXX() supposing you want to match only one row in 'Cat_VEA0 Cost' and you want the row with the maximum price.
Solution
Cost of sale = MAXX(
FILTER(
'Cat_VEA0 Cost',
AND(
'Cat_VEA0 Cost'[From] <= SUM(Sheet2[Sales]),
SUM(Sheet2[Sales]) < 'Cat_VEA0 Cost'[To]
)
),
[Cost]
)
Explanation
Get the maximum [Cost] from all the rows that meet the condition:
MAXX(..., [Cost])
Set the condition to [From] <= SUM([Sales]) <= [To]:
FILTER(
'Cat_VEA0 Cost',
AND(
'Cat_VEA0 Cost'[From] <= SUM(Sheet2[Sales]),
SUM(Sheet2[Sales]) < 'Cat_VEA0 Cost'[To]
)
)