Power BI measurement between fixed Date and calculated Date - powerbi

I'm interested in creating a report comparing a before and after of two equivalent time periods.
The after period is looking at the days from a fixed date (1/10/20) to the most recent case in the tbl_Data table (in this case it is 92 days).
The before period would subtract the calculated 92 days from the fixed date (1/10/20).
I was able to get the days between part fairly easily using the following:
Days_Between =
calculate(
countrows(date_table),
DATESBETWEEN(
date_table[Date_field].[Date],
date(2020,10,01),
MAX(tbl_Data[Date Received])
)
)
However I'm at odds on how to subtract this from the fixed date to get a date range I can filter on easily. Any pointers/ideas would be greatly appreciated.
Cheers

First, I would simplify your days calculation: Days_Between = DATEDIFF(date(2020,10,01), MAX(tbl_Data[Date Received]), DAY ). Then, I would simply subtract the result from the given date. Start date = Date(2020, 10, 1) - [Days_Between]

Related

How i can compare last week average to todays data in Power BI visual?

I want to show an hourly score for today that refreshes every hour. I built it and it works, but now I want it to compare the hourly average for the last week and if it was higher it shows a red arrow up if lower it shows a green arrow down. I don't have a problem adding the arrows as it's very easy, but I've previously added a column to the query that shows if day = today and then used it as a filter inside the visual to show today's data, so when I try to compare the results the filter also affects the calculation I created:
Measure = calculate(average(rawdata[contacts]),rawdata[Week to Average = 1)
week to average is the column that tells if the week was the previous week is simply if(weekcolumn=weeknum(today())-1,1,0)
Do you know any way i can compare last week average to todays data?
Also visual that i used is a matrix
This is just an idea. So if it is enough to solve the case then ok. If it's not it, then, please, add more info about your data table - a screenshot or sample data. how you calculate your average and what do you mean by average? At least what kind of data you are dealing with is it a sum of some values per day, do you have a different number of values for each day? etc.
measure 1:
averContacts = AVERAGE(rawdata[contacts]) -- no CALCULATE()
measure 2:
avrToday =
CALCULATE(
[averContacts]
,TreatAS({TODAY()}, yourTable[DatesColumn])
)
measure 3:
aveLastWeek =
VAR prevWeekEnd = TODAY() - WEEKDAY(Today(),2) -- 2 -> Mon-Sun week format
VAR prevWeekStart = prevWeekEnd - 7
VAR DatesLastWeek = CALENDAR(prevWeekStart ,prevWeekEnd)
RETURN
CALCULATE(
[averContacts]
,TreatAS(DatesLastWeek, yourTable[DatesColumn])
)
measure for your visual
lastWeek_vs_Today = DIVIDE(avrToday ,aveLastWeek)

Prior year returning blanks power bi

Today I come to you with a question regarding a report I am working on finishing up, So I have a lot of Year over year measures in this project, and they all run okay except for 2 of them, its one called "First time complete % 2020" and "Days to first visit 2020", So what is the issue?
When I have a table with claim numbers / customer numbers etc it looks good, I then add the 2021 measures for Current year, this looks good too, when adding the 2020 or prior year measure it is all blank though, and if i do just claim number and remove the Current year measure so i have a table with just prior year and claim number it makes the entire table blank, even the claim number column.
I have attached photos of what I am explaining, the relationship is a 1 to many with 1 being on my calendar side, many on the fact table side.
here is the code for the prior year measure I am using First time complete % 2020 = CALCULATE([Percentage of First Time Complete], 'Calendar(Based on PaidDT Adjusted)'[Year] = 2020)
I have also tried the date add method with CALCULATE([First time complete % 2020], DATEADD('Calendar(Based on PaidDT Adjusted)'[Date], -1, YEAR))
Hope this helps. Thanks
Think about your filter context (filters/slicers/ row level), is there any of them?
If soo, then you need to break this filter by using this kind of calculation:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = 2020))
or something more dynamic:
SomeMeasure = CALCULATE( [YourBaseMeasure], FILTER( ALL('DateTable'[YEAR]), 'DateTable'[YEAR] = SELECTEDVALUE('DateTable'[YEAR])-1 ))

Same Period Last Month

I'm struggling to get the same period of last month.
I want to compare the current month period, for instance, today is 16June2021 so I want to get the sales from May 1st to May 16th.
I'm using this formula but I get the whole month total:
Prev MTD = calculate(sum(Sales[Sales_Amount]),DATEADD(filter(DATESMTD(Sales[Sale_Date]),Sales[Sale_Date]<=today()),-1,MONTH))
Creating a table with DATEADD(filter(DATESMTD(Sales[Sale_Date]),Sales[Sale_Date]<=today()),-1,MONTH), I also get every day of last month.
Is it mandatory to use a Date Table? Already tried but the results came empty.
Is it something regarding my date format? From the import it comes as date/time format.
Thank you very much
Try with:
Prev MTD = calculate(sum(Sales[Sales_Amount]),filter(ALL(Sales[Sale_Date]),Sales[Sale_Date] >= DATE( YEAR(TODAY()), MONTH(TODAY())-1, 1) && Sales[Sale_Date]<=today()))
where order_date between '2022-08-01' and DATE_SUB(CURRENT_DATE(),32)
last month 31 days that's why i am calculated 32 days.
if last month 30 day than you need to calculate 31 days.

Power BI growth rate calculation YoY

I'm having some difficulty getting a YoY change % for values in Power BI. The averages don't come out proper. I've come to understand this is an AVERAGE vs AVERAGEX issue in Power BI.
I need to create charts of year on year growth monthly. So Jan20 % change from Jan 19. I thought what was below was correct, but it is always throwing an issue for the month of February and a few other months. But some of the months are correct. My Measure is below.
Growth =
IF(
ISFILTERED('Oct5_5'[TRAFFIC_DTE]),
ERROR("Check Time Filter."),
VAR PrevMonth =
CALCULATE(
AVERAGE('Oct5_5'[VISITS_AMT]),
DATEADD('Oct5_5'[TRAFFIC_DTE].[Date], -12, MONTH)
)
RETURN
DIVIDE(
AVERAGE('Oct5_5'[VISITS_AMT]) - PrevMonth,
PrevMonth
)
)
Snippet
Can someone please show me how to use the right Average? Thank you so much!
Do You have all calendar days in your traffice_dte?
Probably not. This causes you to go back to a date that does not exist, which causes an error.
DATEADD function work ok if you use it on "calendar" tabel.
Requirement below:
https://dax.guide/dateadd/
The Date table must always start on January 1 and end on December 31, including all the days in this range. If the report only references fiscal years, then the date table must include all the dates from the first to the last day of a fiscal year. For example, if the fiscal year 2008 starts on July 1, 2007, then the Date table must include all the days from July 1, 2007 to June 30, 2008.
There needs to be a column with a DateTime or Date data type containing unique values. This column is usually called Date. Even though the Date column is often used to define relationships with other tables, this is not required. Still, the Date column must contain unique values and should be referenced by the Mark as Date Table feature. In case the column also contains a time part, no time should be used – for example, the time should always be 12:00 am.
The Date table must be marked as a date table in the model, in case the relationship between the Date table and any other table is not based on the Date.

Can't filter properly using a measure as Date in POWER BI

I'm trying to do a report where I have a measure ([10 Days]) with a date stored in it, and I'm using this formula where the measure is necessary as a filter:
VOL NEXT 10 DAYS = CALCULATE([SUM VOLUME];FILTER(fOrders; fOrders[Dates] >= TODAY()); FILTER(fOrders; fOrders[Dates] <= [10 Days]))
The objective is to get the sum of all the volume (which I did using SUMX) and filter it within today and a specific day.
The [10 Days] has to be a measure because is not 10 days straight, but not counting off days from production.
I created a card and the measure shows the intended date, but when I put at the formula, the output is wrong. And if I put the date in the format DATE(YYYY;MM;DD) it works just fine. But I tried DATE(YEAR([10 Days]);MONTH([10 Days]);DAYS([10 Days])) and the sum was still using the wrong date.
You can pass the measure value to a variable and then apply the filter. The following calculation should get you started:
Volume Sum =
VAR EndDate = [10 Days]
Return CALCULATE(SUM(fOrders[Volume]),fOrders[Dates]>=TODAY()&&fOrders[Dates]<=EndDate)
Note: The above formula is written under the assumption that [10 Days] is always higher than today. If it's not then modify the formula accordingly.
Hope this helps.