Cumulative sum with time-intelligent slicer using dax in powerbi - dax

I'm new to Power BI, and I'm working on this measure to show cumulative sum on specific time period.
The case and what I want:
I have one Calendar table [DateKey], and main data table [Data], they have relationship based on column date.
I need to show a visual of line & clustered column chart and a time slicer, in which cumulative sum of revenue based on the slicer.
For eg: I have revenue table for July, I put out the DateKey[Month] column as slicer, when I choose July, the visual would show the cumulative sum of Revenue in July (from 1st to 31st July)
When I choose August, the visual would show cumulative sum Revenue in August (from 1st to 31st August)
What I tried: I used the following DAX
Cumulative Sum Rev = CALCULATE(
SUM(Data[Revenue]),
FILTER(
ALL(Data),
Data[Date]<=MAX(Data[Date])
)
)
Actual outcome: It did create a cumulative sum line, but it was fine for July. If I choose August in slicer, it would be cumulative sum from July to August. What I expected is the cumulative sum will begin from August, not from July.
I tried another solution, which is using ALLEXCEPT instead of ALL, but it does seems not working for date column (you can see my measures in the pbix files already have it, but to filter another column [Lead_type], which works perfectly fine for another slicer)
Cumulative Sum Rev = CALCULATE(
SUM(Data[Revenue]),
FILTER(
ALLEXCEPT(Data,Data[Lead_type]),
Data[Date]<=MAX(Data[Date])
)
)
Please help to show me where I was wrong.
Here is the link to my pbix file, it include what my visual would be and my measure:
https://1drv.ms/u/s!As4H0zrXywmbhaVFDprZ6RJmFUMbbg?e=l4Wxe5

What you are after is a "Month-to-date" measure. This is a built-in time intelligence function in DAX - you can also make your own version using the correct variables and DAX syntax - this carries more flexibility. However, for this case, this should do the trick:
First add a measure that sums the Revenue column. It is always smart to have these simple aggregating measures - when you use these measures in other measures, they are wrapped in a CALCULATE statement automatically, and this avoids some confusion down the road:
Revenue Amount := SUM ( Data[Revenue] )
Then add a TOTALMTD measure, which takes the first measure as the first argument, and your date column as a second argument. Note: the date column is in your DateKey table - do not use the date column in your fact table for this:
Cumulative sum =
TOTALMTD (
[Revenue Amount] ,
DateKey[Date]
)
You should also read up a bit on calendar tables and the difference between creating a table using ADDCOLUMNS and adding individual calculated columns on top of a calculated table. I would start here: https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Related

Power Bi matrix subtotal is not the sum of the values in the column

I am trying to create a "meetingroom occupancy" matrix in Power BI. The raw data contains bookings per day per Room. The maximum daily available time per room is 12 hours. I have created a Date Dimension Table for the dates.
I have tried to change datatypes, added the available time column in the query editor, added the available time as DAX column and as calculated measure, but all with no success. I have changed the available time for Room B to 1, and the result of the Subtotal was 13, so it looks like subtotals is only summing unique values, but I do not know how to solve this.
Could someone please explain to me what is happening and how I could solve this?
The input data is as follows:
And my Date_Dimension is as follows:
This is the current and desired result:

Dax measure to highlight the difference between slicers

I have a Power BI report that should highlight the difference of ETA column ( see below) by the comparison of 2 snap dates (if the ETA value changes from the date of the first selected date in the slicer, in comparison to the second slicer, the ETA cell should be colorized). I need a DAX measure that would help me do that

Power BI Matrix Totals calculating incorrectly for

I am currently having an issue with the power bi Matrix Calculation when using dax. I need to calculate the Running total for overtime per fortnight, which I have achieved using the following
Lieu running total to Date = CALCULATE(SUM('Table1'[OT]),FILTER(ALLSELECTED('Calendar'[Date]),ISONORAFTER('Calendar'[Date], MAX('Calendar'[Date]), DESC)))
However I now need to calculate the excess hours (OT) which I have used the following to calculate people over 90 hours(additional 10 hours)
Excess Lieu2 = IF([Lieu running total in Date]>=160,[Lieu running total in Date]-160,0)
The issues is the the grand totals is calculating the entire total - 160
The the last few total rows as well as the grand total are aggregating incorrectly...ANy help is greatly appreciated. A Dax solution is needed as this will need to be dynamic as the employees names will be added
Add a new measure with below code and add that measure to your matrix.
Total_Lieu_running_total_to_Date =
SUMX (
SUMMARIZE (
table,//add the table from which the pay period end date is coming
table[pay period end date],//date column which you are using in matrix
"Lieu_running_total_to_Date",
[Lieu running total to Date] //measure which you using currently
),
[Lieu_running_total_to_Date]
)
Note:- Please add some sample data so it would help other to give you solution quickly.

Is there any way to use first and last functions in rpd for one measure column in OBIEE?

I am building an rpd and one of the requirements was the following. We have one measure column DEBIT_ALL in a fact table . This is a sum of all debits that client had since the creation of that client's account. That is this sum always accumulated whenever there is an debit operation.
So in OBIEE users create analysis to see the Debit_all value for some period using date1 and date2 in filters, or just giving month or year value. The easiest way to calcute this amount for some period is to substract sum in date1-1 from sum in date2.
That is value of debit_all measure for period from date1 to date2 is equal to:
value in date2 - value in (date1-1)
Can we do this in rpd admin tool? I had an idea to use first and last functions but couldnt find a proper way.

How to get minimum value from range date in DAX

I need to get a calculated measure of the minimum date of a range of values, ie I have a fact table with a date and two measures. When I filter by range date, I need to get the second measure of the minimum date of that range, in the example, the measure 1 of 1st january, something like this:
https://db.tt/6jKBPRCr
The picture on the left is as I have the data in the fact table, data from the right as they should be when I filter from date (from 1st to 6 january). The measure 1 is added for a group, and measure 2 is the minimum value of the range of dates and must be repeated for each resulting record (highlighted).
I need the solution for PowerBI Desktop (DAX)
I would greatly appreciate your help with this.
Thank you for your time

Resources