Power BI calculate DAX measure cumulatively - powerbi

I can't configure how to calculate DAX measure cumulatively. The DAX measure by it self looks like this:
UpdateTicket_ = CALCULATE(Logging[LogDistcount_], Logging[Step] = 7) # DAX measure to filter distinct ID by some condition.
LogDistcount_ = DISTINCTCOUNT(Logging[TicketId]) # DAX measure to calculate distinct ID presented in the featured dataset.
The ploblem is that formula construction to calculate cumulatively doesn't allow to sum DAX measure. I mean this: =CALCULATE(SUM(UpdateTicket_)... The formula doesn't give an option to select UpdateTicket_ to make a SUM of it. This measure doesn't appear in the selection list of the SUM formula at all.
Currently output of the UpdateTicket_ measure looks like this:
StartTime_DateOnly
UpdateTicket_
08.11.2022
950
09.11.2022
1056
10.11.2022
1056
11.11.2022
1056
12.11.2022
1056
13.11.2022
1056
What I am looking for:
StartTime_DateOnly
UpdateTicket_
UpdateTicket_Cumulatively
08.11.2022
950
950
09.11.2022
1056
2006
10.11.2022
1056
3062
11.11.2022
1056
4118
12.11.2022
1056
5174
13.11.2022
1056
6230

I hope you can accept the following solution:
Let Power BI create the measure for you by going to Quick measure - Running total
You'll get the following expression:
UpdateTicket_Cumulatively =
CALCULATE(
SUM('Table'[UpdateTicket_]),
FILTER(
ALLSELECTED('Table'[StartTime_DateOnly]),
ISONORAFTER('Table'[StartTime_DateOnly], MAX('Table'[StartTime_DateOnly]), DESC)
)
and a table like this:
Note that this works with both measures and columns.

Related

Power BI count null rows

I have two columns. Both have a general key INT value called TicketId, but one table has less TicketIds than another table. Both tables have different quantity of columns, so =EXCEPT() formula wouldn't fit.
For example, the current counting of rows looks like this:
Dates
Tab1
Tab2
08.11.2022
1058
950
09.11.2022
1058
1056
22.11.2022
2342
302
I am looking for a DAX measure forluma that will calculate TicketIds that exist in Tab1, but doesn't exist in Tab2. It should be not a formula like 1058 - 950 = 108. Because after there will be drillthrough to show all the TicketIds that were calculated (exist in Tab1 and doesn't exist in Tab2).
Dates
Tab1
Tab2
Tabcross
08.11.2022
1058
950
108
09.11.2022
1058
1056
2
22.11.2022
2342
302
2040
Let's say you have a model like this:
and your datasets like this:
Define your measures like this:
OnlyTable1 = COUNTROWS(VALUES(table1[TicketId]))
OnlyTable2 = COUNTROWS(VALUES(table2[TicketId]))
ID_Difference = COUNTROWS(EXCEPT(
VALUES(table1[TicketId]),
VALUES(table2[TicketId])
))
Then if we put it on a table visual:
Here is how to apply EXCEPT() to your problem:
TabDiff =
EXCEPT (
VALUES ( Tab1[TicketId] ),
VALUES ( Tab2[TicketId] )
)
Note that this creates a calculated table.

Distinct count of values based on date in DAX

I have a table like shown below:
ID
Date
Asset
Location
145
7/29/22
A
Market
145
7/30/22
A
Warehouse
145
7/29/22
B
Market
145
7/29/22
C
Truck
150
7/30/22
B
Market
145
7/29/22
D
Market
145
7/30/22
A
Market
What I am trying to accomplish is to get a distinct count of IDs for each date with a location filter as well. So I would want a count of ID based on the slicer selected Date of 7/29/22 AND 7/30/22 for the Market Location. The desired result is 2 for the selected dates from the date slicer which directly corresponds to the date column in the table.
I was trying to use this DAX formula and wasn't getting anywhere....
IDsMarket =
CALCULATE (
DISTINCTCOUNT ( 'Products'[ID] ),
ALL ( 'Products' )
)
I have a measure dropped onto a card. I should have specified that. My apologies. I need 1 measure to show me the combined count for the two days selected.
I tried this with countrows as well but of course the result wasn't distinct... Any help would be greatly appreciated!!
The formula you're looking for is
IDsMarket =
CALCULATE(
DISTINCTCOUNT('Products'[ID]),
'Products'[Location] = "Market"
)
The resulting Table will look like this
But if you put the measure on a Card visual, you'll get
So in DAX the same measure can yield 1000 different values - depending on the filter context.
I created a conditional column in Power Query and combined the ID with the "day" number from the date column which allowed me to then do a distinct count on that combined custom column which produced to correct answer. Sorry for all the confusion. One of those days.

Power BI - Show zero/null value on line chart with dates

I'm using a simple table like this to make a report in Power BI:
Order number
Order date
Turnover
001
30/1/2022
10 €
002
30/1/2022
20 €
003
2/2/2022
15 €
I need to create a line chart showing all the dates, even where I have no data (no orders for that day). This is currently how is shown:
You can notice that the 1/2/22 and 3/2/22 are missing due to no order, but I want them to be visible and the value should be 0. This is also affecting the average line because it's calculated based on the days with data, but I need to put into account also the 0-turnover days.
I tried to use the "Show items with no data" on the date dimension and switch the X axis from Continuous to Catergorical and the other way around. I also tried to create a new metric like this:
Total Turnover = IF(ISBLANK(SUM(Orders[Turnover (EUR)])), 1, SUM(Orders[Turnover (EUR)]))
but it's not working.
If I understand your business requirement correctly, you are going to need to do three things:
Make sure you have a date-dimension table in your model. Build the relationship based on your [Order date] column.
Refactor your [Total Turnover] measure as such:
Total Turnover =
VAR TotalTurnover = SUM( Orders[Turnover] )
RETURN
IF(
ISBLANK( TotalTurnover ),
0,
TotalTurnover
)
Build your line chart using the [Date] column from your date table.

Calculate total variance in power bi with dax

I have 3 measures:
1) total_trx = SUM(mytable[trx])
2) trx_prev_month = CALCULATE([total_trx], DATEADD(calendar[date], -1,MONTH))
3) monthly_var = DIVIDE([total_trx],[trx_prev_month])-1
If I add a waterfall viz, x-axis with month, it gives me the % of monthly variation and a TOTAL bar at the end that sums all the variations.
I need to reproduce that total number in order to show a KPI as in "so far, we've increased ...%", changing when using a date slicer.
Seems like sum(monthly_var) is not allowed.
Any ideas?
Thank you very much.
Edit1: sample with date filter = Last 4 months
Jul 100 0%
Aug 110 10%
Sep 90 -20%
Oct 80 -10%
Total: -20% <- need a dax to calculate this number and show just -20%
Then if I change the filter to, for example LAST 6 MONTHS, I need to calculate it up to May
In order to get the desired result we will use an intermediate table in our query that will summarize the results by months:
use this code and replace calendar[Year Month] with your Year month column :
SUMX(
SUMMARIZECOLUMNS(calendar[Year Month],"Monthly_int_var",[monthly_var]),
[Monthly_int_var]
)

How to multiple two columns in a row with max date in PowerBi?

This is my first PowerBi report. 
I've a table structure like this
TransDate UnitsAsOf Price InvestedAmount Stock
01/02/2020 10 12.4 124 APL
01/03/2020 20 13 260 APL
01/05/2020 21 15 315 APL
01/10/2020 1 111 111 BPL
And this is the table Visualization I'm creating
Stock Total invested (Summarized column) Current Value
APL 699 THIS IS A MEASURE column
BPL 111
I just couldn't figure out how to get max(transDate) for each stock and multiple it with the Price of that row?
Any help please?
You can do it like this
measure =
SUMX(TOPN(1, YourTable, YourTable[TransDate], DESC), YourTable[Price] * YourTable[InvestedAmount])
the TOPN will return you the row with the latest date, and in the SUMX you use the fields from that row.
OPTION-1
You can simply create this following measure-
max_date = MAX(your_table_name[TransDate])
Now add a table visual with column - Stock, InvestedAmount (Default SUM applied) and New Measure max_date. The output will be as below-
OPTION-2
You can also add all 3 column - Stock, InvestedAmount and TransDate directly and select Latest for TransDate as shown below and the output will be same-