How to capture a measure result at certain date? - powerbi

I have 3 measures(Measure1, Measure2 & Measure3) in my dataset. I have a "Sprint Begin" column in the dataset, what I wanted to do is calculate "Measure1" on every Sprint Begin date and capture that result. and calculate "Measure2" only after 7 days of Sprint Begin date, and calculate Measure3 only after 14 days of Sprint Begin date, each measure value should be captured for 14 days until the next Sprint Begin. I want to refresh each measure only every 14 days from the last refresh of each measure.
I want to calculate & refresh Measure1 when Max(Sprint begin)=today() only, else show the previous value( from last refresh)..Calculate and refresh measure2 when Max(Sprint begin)+7=today() only, else show the previous value( from last refresh)...calculate and refresh measure3 when Max(Sprint begin)+13=today() only, else show the previous value( from last refresh). those measures can be shown in a card visual.
Team Sprint Sprint Begin Sprint End
Team1 Sprint1 1/1/2021 1/15/2021
Team1 Sprint2 1/16/2021 1/30/2021
Team2 Sprint1 1/1/2021 1/15/2021
Team2 Sprint2 1/16/2021 1/30/2021
I was trying to store the measures in separate new tables using summarize(by Team & Sprint columns) and refresh them on those certain days manually but my source tables are big I could not even store them in separate tables because of memory issues. Any help?

you can create a master table for just storing the informations like
Sprint | Sprint Begin | spring end
this will help you to calculate in your measure by referring current date with the sprint begin and end date.

Related

How to show the records which are part between selected date range in Dax

I have a below table in Power BI. This table will have the details of campaigns which are ran on specific period.
Campaign Name StartDate Enddate
AAA 01-05-2022 30-04-2022
BBB 01-04-2022 30-04-2022
CCC 01-04-2022 30-04-2022
DDD 01-04-2022 30-09-2022
EEE 01-03-2022 30-09-2022
FFF 01-03-2022 30-09-2022
Now i am using the start date in the slicer. so if i select date range of Apr-22 to Jun-22, table should display whatever campaigns which are active between the selected period. In this case, it should display all the values from the above table, because all the campaigns are between Apr-Jun. but in my case, last two rows are not displaying since the start date is in March but these campaigns are also active during the period of Apr-22 to Jun-22. is there a way we can create some measure to show the campaigns, even if start date before selected slicer date range but end date falls between the selected date range?
You can try smth like this. The measure should return 1 for “active” if a company name is in scope and total number of active in total. But it would be better to create a DateTable as Ozan Sen advise. Otherwise you can get a wrong output - a slicer will return max and min dates that you have in table not as slicer shows. For instance your slicer shows you the first date as 01 Jan, but in your facts the minimum is 3 Jan, so, this you will get as minDate. The problem can come if the endDate is 02 Jan, the measure will not count it, because the minDate=03 Jan. With a Date table you'll avoid this kind of problem. I didn't check the measure, so I'm not 100% sure it works.
VAR minDate =Min('table'[startDate])
VAR maxDate =Max('table'[startDate])
VAR noOfCompNames =
CALCULATE(
CountRows(table)
,OR(
AND('table'[startDate]>=minDate,'table'[startDate]<= maxDate)
,AND('table'[endDate]<=minDate,'table'[endDate]>=maxDate
)
)
RETURN
noOfCompNames

Graph a daily amount in between two dates

The source table has a table with a single amount and a revenue start and revenue end date. I need to graph the amount over the period by day in PowerBI.
For example:
Looking at the second row the total amount is 730 but I need to calculate a daily rate and display this each day for the revenue period. So if I had a bar chart for this row I would need to show it as 16 April has 34.76, 17 April has 34.76 and so on until 6 May which is the revenue end date. I've tried using between dates but cant seem to get it working.
You can use Power BI's CALENDAR() function to create a table of dates ranging from the minimum revenue start date to the maximum revenue end date.
Dates = CALENDAR(MIN(BookFees[Revenue Start Date]),MAX(BookFees[Revenue End Date]))
Then you can create a calculated column in the Dates table for the daily revenue.
Daily Revenue = Calculate(SUM(BookFees[RevenueDayAmount]),FILTER(BookFees,BookFees[Revenue Start Date]<=Dates[Date] && BookFees[Revenue End Date]>= Dates[Date]))
Here is the resulting bar chart:

Finding Previous year Sales in Power BI with week number

I am trying to find the Previous year sales for the same week in Power BI.I dont have any date column.
I have two table one is FACT Indicators table as shown below:
and one sales table( Fact Sales table):
I want to create one calculated field namely(Sales Previous Year) to show the previous year sales for the same week .
In 'Fact Indicators' table 'PY 52 week flag' filed shows if this week id is Previous year or not.
Week column shows the week number from 1 to 52 weeks .
Week Id shows the unique number per Market key.
'Market_Week Id Key' is the common joining key between FACT Indicators table and Fact Sales table
Please help me to find the formula for calculated field.I dont have the date field in my raw data
Every time you deal with anything related to dates, you will need to add what we call a date dimension. It will save you tons of headaches. Once you have it in you will be able to hook it into the creation of the calculated filed.
you can google power bi or ssas date dimension and find tons of information on it.
Yeah! I guess SQL Technical team can be a tough crowd.... Well! In this case, I would recommend bringing the Year into FactSales Table from Fact Indicator . You have two options here with physical relationship set up between Market Week Id Key in both tables you can build a calc column with
Year = CALCULATE(VALUES(FactIndicators[Year]))
or without relationship use LOOKUPVALUE on WeekId
Year = LOOKUPVALUE(FactIndicators[Year], FactIndicators[WeekId], FactSales[WeekId])
Sales Last Year calc colum :
SalesLastYear =
CALCULATE (
SUM(FactSales[SalesThisYear] ),
TOPN(1,
FILTER(
FactSales,
FactSales[Year] < EARLIER(FactSales[Year])
&& FactSales[Key] < EARLIER(FactSales[Key])
)
)
)

Filter table based on a specific date plus 7 days

I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.

How to calculate last 4 any weekdays sales in power bi

I want to calculate last 4 any weekdays total sales.Based on filter max date.
Example: I have 2 filter
1. Date range(From -To)
2. Week Day(Like Mon,Tue Etc.)
I need total sales for last 4 Monday or Tuesday (as per above filter ).And Last 4 weekdays will be calculated based on To-date in filter.
Like To-date is 31-Dec'18 then last 4 Tuesday will be 4,11,18,25 Dec.
Thanks in advance for the help.
Nitika, the best way to do that is creating another table to put a 'Dimension' with dates, int that you can put, weekday, day, holiday, year, month...
Something like that:
Do You Need a Date Dimension?
Why use a Date Dimension Table in a Data Warehouse
Doing that you can reference your atual date with this table, and get just the weekday that you are looking for