How to split value over time in PowerBi? - powerbi

I have a value that is valid for a period of time, for example, 1200 minutes overtime period of 2020-01-01 to 2020-12-31.
format:
Start date, End date -> total time in minutes
2020-01-01, 2020-12-31 -> 1200
What's the best way to be able to split it by day/week/month (i have a calendar table ready)?
The end goal is to present it on the graph cumulatively as well as additional data from the other table that will show progress against this target.
Additional data is logged per day in the format:
DATE -> VALUE in minutes (not cumulative)
so (reflected in the 2nd chart below):
2020-02-05 -> 300 minutes
2020-05-22 -> 200 minutes
2020-07-12 -> 100 minutes
2020-09-02 -> 300 minutes
2020-10-05 -> 100 minutes
2020-11-09 -> 100 minutes
2020-12-12 -> 100 minutes

You could simply create an index column in your date table and then scale that one according to your desired trend:
Expected = RANKX ( 'Calendar', 'Calendar'[Date], , ASC ) * 1200 / 366

Related

DAX - How to use DATESBETWEEN in SWITCH function

I am having a bit of tough time wrapping my head around this. I have a column based on response time in hours and our company's SLA (service level agreement) is that all incoming inquires should be answered within 2 days (the response time in hours is total hours spent on responding to inquiry).
The problem is that our company operates with winter time (7 h 45 min) and summer time (7 h). My dataset consist both and I want Power BI to differietiate winter and summer time when I try to compute SLA. In winter time 1 working day = 7 h 45 min and in summer time = 7 h. I have just used the average of summer/winter time = 7 h 30 min. The SLA column consist 3 data types, "Innen en arbeidsdag", "Innen to arbeidsdager" and "over 2 arbeidsdager".
I have used the following syntax:
SLA = SWITCH(TRUE(),Response time in hours>15, "Over to arbeidsdager", esponse time in hours>7.5, "Innen to arbeidsdager", Response time in hours<=7.5, "Innen en arbeidsdag")
How can I use DATESBETWEEN in this syntax to tell Power BI that Response Time YTD column from 15th May to 15th September is summer time, Working day = 7 h?
Just as an idea, I wouldn't use DATESBETWEEN. If you want to input dates directly to logically categorize your work seasons, try this:
SWITCH(TRUE()
,'Date'[Date] >= DATE(2022,5,15)
&& 'Date'[Date] <= DATE(2022,9,15)
,7
,BLANK()--You can carry on with logic for other seasons
)
I am using this syntax on a date table, but you can do this with any table that has a date column.
My dataset is called 'Masterdata' and my columns looks like this:
Svartid i t SLA
6,12 Innen en arbeidsdag
11,73 Innen to arbeidsdager
20,42 Over to arbeidsdager
1,07 Innen en arbeidsdag
etc etc
My syntax so far:
SLA = SWITCH(TRUE(),Masterdata[Svartid i t]>15, "Over to arbeidsdager", Masterdata[Svartid i t]>7.5, "Innen to arbeidsdager", Masterdata[Svartid i t]<=7.5, "Innen en arbeidsdag")
So how can implement
SWITCH(TRUE(),'Date'[Date] >= DATE(2022,5,15) && 'Date'[Date] <= DATE(2022,9,15),7,BLANK()
In my syntax?

Dax calculate a metric for another day in the calendar table

I have a table with a date column and a money column:
Thedate CashCollected
2039-12-28 100
2039-12-27 200
2039-12-26 300
2039-12-25 400
2039-12-24 500
2039-12-23 600
2039-12-22 700
2039-12-21 800
and then I have the date table with the date and the previous working day calculated following some specific conditions:
TheDate PrevItWorkDay
2039-12-28 2039-12-27
2039-12-27 2039-12-23
2039-12-26 2039-12-23
2039-12-25 2039-12-23
2039-12-24 2039-12-23
2039-12-23 2039-12-22
2039-12-22 2039-12-21
2039-12-21 2039-12-20
I would like to calculate in DAX a measure which gives me the sum of cash collected for the previous working day in the date table:
TheDate PrevItWorkDay
2039-12-28 200
2039-12-27 600
2039-12-26 600
2039-12-25 600
2039-12-24 600
2039-12-23 700
2039-12-22 800
2039-12-21
How can I do this?
PrevWorkingDaySum =
CALCULATE(
SUM(TransactionTable[CashCollected]) ,
TransactionTable[Thedate]= SELECTEDVALUE(DateTable[PrevItWorkDay])
)

BigQuery convert Month Year column to timestamp or date

I have a table
Year_month amount
08-2021 100
09-2021 200
10-2021 300
I want to add a column Month to be
Year_month Month amount
08-2021 01-08-2021 100
09-2021 01-09-2021 200
10-2021 01-10-2021 300
It depends of the type of data you have. check below code:
with sodata as (
select '08-2021' as Year_month_string, PARSE_DATE("%m-%Y", "08-2021") as Year_month_date, 100 amount,
union all
select '09-2021',PARSE_DATE("%m-%Y", "09-2021"), 200
union all
select '10-2021',PARSE_DATE("%m-%Y", "10-2021"), 300
)
SELECT Year_month_string,FORMAT('01-%s',Year_month_string) as using_format,FORMAT_DATE("%d-%m-%Y", Year_month_date) as using_format_date,amount from sodata
output
Row
Year_month
using_format
using_format_date
amount
1
08-2021
01-08-2021
01-08-2021
100
2
09-2021
01-09-2021
01-09-2021
200
3
10-2021
01-10-2021
01-10-2021
300
To see more details about the functions used please go to this links:
Format (string)
Format Date
You can use Parse date function
SELECT PARSE_DATE("%m-%Y", "08-2021")

Spilt Revenue By Percentages in right year buckets in Power BI

I have a list of product with revenues across 3 years. However I would like to split the revenue by 60 % and 40% for each year.
For instance:
Book -> 2020 -> 15mil
Book -> 2021 -> 18mil
Book -> 2022 -> 12mil
Therefore in Power BI the revenue should appear as:
2020 -> 60% x 15
2021 -> 40% x 15 + 60%*18
2022 -> 40% x 18 + 60% x 12
2023 -> 40% x 12
How can I code this in Power BI to ensure that the revenue are split accordingly?
Update:
I have tried to do a 60% and 40% split column and additional column of Year +1. How do I add them up on Power BI based on year?
I assumed some data model like the following:
[SalesAmt] = SUM(paid_price)
If we now create a table out of the year and [SalesAmt] we get the following. (My sales values were created for testing purposes)
Now for my understanding: You want to display the SalesAmt (which exact Measure doesn't matter) multiplied by 60% and add the SalesAmt from the previous year multiplied by 40%.
For this we can use the DAX formula SAMEPERIODLASTYEAR(), it takes one argument, the date-field for which you want to retrieve the last year's pendant.
[SalesAmt Buckets v1] =
SALES[SalesAmt] * 0.6
+ CALCULATE(SALES[SalesAmt], SAMEPERIODLASTYEAR(DATES[fq_date])) * 0.4
Explanation to this formula:
We calculate the current year's [SalesAmt] and multiply it by 60%, then we calculate [SalesAmt] and changing the filter context for this calculation by CALCULATE(). At the end we multiply by your 40% and return the result.
Notice how it is less for the firs year (2019), that's because we don't have a previous year for the row context year 2019, so we just retrieve the current year's value times 40%.
For the next years it's correct being 2020 = 40% * 79 + 60% * 95 = 85.

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]
)