Cumulative total by group in Power BI (DAX) - powerbi

After googling for two pages, I'm struggling to find a simple way to create a cumulative sum measure by date and item in Power BI (using DAX). I have a table which contains:
Username
Date (DD-MM-YYYY)
Number of requests in that day
I have managed to obtain the cumulative sum by using the following expression (extracted from DAXPatterns):
CALCULATE (
SUM ( Table[Requests] ),
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date] <= MAX ( 'Date'[Date] )
)
)
But I would like to obtain a measure indicating how many requests have been made by a user up to a certain date.
Is there a simple way to do this?

Create calculated table using SUMMARIZECOLUMNS function and apply filter that you need on the top of that calculated table.
YourCalcTableName =
SUMMARIZECOLUMNS (
'UsernameTable'[Username],
'Date'[Date],
"Number Of Requests", SUMX ( 'UsernameTable', 'UsernameTable'[NumberOfRequests] )
)
This calculated table essencialy produces 3 column table with user name, date and number of requests sent by this user on this date.
SUMMARIZECOLUMNS

Related

DAX PowerBI filter against another Table

I have two tables: Sales and VIPS. The sales table will include customers who are not in the VIP Customer table.
I want to create a Measure to find a distinct count of VIP Customers in the Sales table who have bought a sale and a non-sale product.
I’ve been trying to filter the Sales Table on the VIP Customer table, to get sales only relating to VIPs and then Distinct Counting those but I’ve had no success.
VIPSales =
CALCULATE (
DISTINCTCOUNT ( Sales[USERID] ),
Sales[SaleItem] = 1 || Sales[SaleItem] = 0,
CROSSFILTER ( Sales[UserID], VIPS[UserID], ONEWAY_LEFTFILTERSRIGHT )
)
How about counting which VIPs have two distinct SalesItem values?
VIPSales =
COUNTROWS (
FILTER (
VALUES ( VIPS[UserID] ),
CALCULATE ( DISTINCTCOUNT ( Sales[SaleItem] ) ) = 2
)
)
This assumes there is a one-to-many relationship where VIPS filters Sales. If not, then you'll need an extra argument for CALCULATE to do the filtering.

Creating multiple cumulative line graphs in Power BI with DAX

I'm trying to figure out how to create a cumulative line graph in Power BI. The problem I'm having is I have a lot of variables that need to fit in and I'm having some trouble to make it work. I've got the following columns in a table.
Product certification
Delivery date
Product volume
The product volume column has an associated data and certification number to each volume row. I want to create a graph that has cumulative lines for each product certification.
To create the cumulative graph by volume I've written a DAX formula that goes like this:
Cumulative volume =
CALCULATE (
SUM ( CONCRETE[Product Volume] ),
FILTER (
ALL ( CONCRETE ),
CONCRETE[Delivery Date] <= MAX ( CONCRETE[Delivery Date] )
)
)
However, this doesn't account for the Product certification. It only sums up the total volume to date.
Anyone have any thoughts on how to correct this?
Thanks so much for any help!
Just use Date column while filtering for ALL,
Cumulative volume =
CALCULATE (
SUM ( CONCRETE[Product Volume] ),
FILTER (
ALL ( CONCRETE[Delivery Date] ),
CONCRETE[Delivery Date] <= MAX ( CONCRETE[Delivery Date] )
)
)
I hope it helps!!

Calculate cumulative sum of summarized table column

I having trouble calculating the cumulative sum of a column on PowerBI.
I have a big offer table and I want to run a pareto analysis on it. Following many tutorials, I created a SUMMARIZED table by offer and a sum of their sales. So the table definition is:
summary = SUMMARIZE(big_table; big_table[offer]; "offer sales"; sum(big_table[sales]))
Many of the forums and stackoverflow answers I found have direct me to the following formula for cumulative sum on column:
cum_sales =
CALCULATE(
sum([offer_sales]);
FILTER(
ALLSELECTED(summary);
summary[offer_sales] <= max( summary[offer_sales])
)
)
However the resulting table is not correct:
What I need is simply to have the offers ordered by sales descending and then add the current row's sales amount to the previous row's sales,
So I excepted numbers closer to:
1st row: 1.5M
2nd row: 2.1M
3rd row: 2.6M and so on
But (maybe) because of my data structure and (certainly) lack of knowledge on how PowerBI works, I'm not getting the right results...
Total Amount = SUM ( 'Fact'[Amount] )
Offer Visual Cumulative =
VAR OfferSum =
ADDCOLUMNS (
ALLSELECTED ( 'Offer'[Offer] ),
"amt", [Total Amount]
)
VAR CurrentOfferAmount = [Total Amount]
VAR OffersLessThanCurrent =
FILTER (
OfferSum,
[amt] <= CurrentOfferAmount
)
RETURN
SUMX (
OffersLessThanCurrent,
[amt]
)
There's no need to pre-aggregate to a summary table. We can handle that as in the measure above.
This assumes a single fact table named 'Fact', and a table of distinct offers, 'Offer'.
Depending on what you're doing in terms of other filters on 'Offer', you may need to instead do as below:
Offer Visual Cumulative =
VAR OfferSum =
ADDCOLUMNS (
ALLSELECTED ( 'Offer'[Offer] ),
"amt", CALCULATE ( [Total Amount], ALLEXCEPT ( 'Offer', 'Offer'[Offer] ) )
)
...
The rest of the measure would be the same.
The measure is fairly self-documenting in its VARs. The first VAR, OfferSum is a table with columns ('Offer'[Offer], [amt]). This will include all offers displayed in the current visual. CurrentOfferAmount is the amount for the offer on the current row/axis label of the visual. OffersLessThanCurrent takes OfferSum and filters it. Finally, we iterate OffersLessThanCurrent and add up the amounts.
Here's a sample:

Cumulative average on power bi

I have a table which contains a list of products scores by date:
From this table, I have to make a plot of the cumulative percentage of each quality by date.
At this moment I have the percentage of each class by day:
For that I used this measurement:
Measure =
CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) ),
ALLEXCEPT ( Table1, Table1[Score] )
)
/ CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( ALL ( Table1 ), Table1[Date] = MAX ( Table1[Date] ) )
)
But this only considers the percentage of each day. I need to consider all previous dates. E.G. for day 2 I need to consider days 1 and 2, for day 3 I need to consider days 1,2,3 and so on.
How can I accomplish this?
in my opinion, you need a calendar for the date first, you can create a table easily bay dax function =CALENDARAUTO() And mark it as a calendar table,
After that, you can use a DATEMTD or a DATEYTD function for your coding purpose.
here are the steps:
1 - https://learn.microsoft.com/en-us/dax/calendarauto-function-dax
select left pane --> table --> modelling / create table and add dax formula
2- reference the table as a date table, right click on the table from the right pane
after then you can use data functions like YTD MTD ,
new measure :
1st mesure : AVG1 = AVG(DATA_)
2nd measure : YTD AVG ALL = CALCULATE([AVG1];DATESYTD(CALENDAR[DATE]))
REF: https://learn.microsoft.com/en-us/dax/dateadd-function-dax
then you can use MONTH(CALENDAR(DATE)) on left and YTD AVG as a value at any table...
regards.
SUNAY

Running Total with Slicer from another table

I have a running total dax measure that works. Problem now is that the slicer on the page is coming from another data set which is linked to the source table of running total data set and when you select the slicer it doesn't filter anything.
Homes Connected =
CALCULATE (
SUM ( refv_FTTH_HomesConnected[ActualHomesConnected] ),
FILTER ( ALL ( refv_FTTH_HomesConnected ), refv_FTTH_HomesConnected[Month_sort2] <= MAX ( refv_FTTH_HomesConnected[Month_sort2] ) )
)
Is there a way to incorporate the columns from the other dataset to get the desired result?
The ALL in your FILTER removes any slicer selection filtering.
Try using ALLSELECTED instead.