I have data for last 2 months of a year 2018.I have created all the necessary measures and columns as well as tables following this tutorial http://sqljason.com/2018/03/display-last-n-months-selected-month-using-single-date-dimension-in-powe....This is my dashboard.
but when i am choosing the date as August 2018 and selecting the slider to show the data for last 2( or any number) months then i am not getting the required result. This is the measure i am using
Scan (last n months) =
CALCULATE (
COUNT('Scan'[Data ID]),
DATESINPERIOD ('Date'[Date],MAX('Date'[Date]),-[N Value],MONTH )
)
No data for previous months for August 2018
No data for previous months of August 2018
Related
I have a daily sales data for 3-4 years. I want to create the YTD and Prior Year To Date sales measure that will be updated daily. That is it should always be from beginning of the year (selected) to TODAY or the last day of the data (1 day lag from today and max date).
I used Sameperiodlastyear but it is problematic at the beginning of the month as it compares say Jan 1, 2022-June 8 2022 with Jan 1, 2021 with June 30, 2021.
Any suggestion how I can create a modified prior year to date measure to address this nuance?
This is a standard solution for the case. First, you get all dates, with a DATESYTD() function, for the current year or last visible year up today or last visible day, then you offset it.
SAMEPERIODLASTYEAR(DATESYTD(‘Date’[Date]))
It is equal to
DATEADD(DATESYTD(‘Date’[Date]),-1,YEAR))
Try this if you want to get exact days set:
VAR FirstDayThisYear =
SAMEPERIODLASTYEAR(STARTOFYEAR(‘Date’[Date])
VAR LastDayThisYear =
SAMEPERIODLASTYEAR(
LASTDATE(‘Date’[Date])
)
VAR SetOfDates=
DATESBETWEEN(
‘Date’[Date]
,FirstDayThisYear
,LastDayThisYear
)
RETURN
SetOfDates
I'm building a Power BI dashboard that includes actual cost vs budget. Summarizing the cost is not a problem. The budget amount is entered in a table as a weekly amount, for example $1,000. We use a custom accounting calendar that dictates the number of weeks per month. The second month of each quarter is 5 weeks while all other months are 4 weeks. Here's what it looks like:
January is 4 weeks
February is 5 weeks
March is 4 weeks
April is 4 weeks
May is 5 weeks
June is 4 weeks
July is 4 weeks
August is 5 weeks
September is 4 weeks
October is 4 weeks
November is 5 weeks
December is 4 weeks
I need a looping variable in DAX that will simply count the number of weeks based on the months chosen with the month slicer. Then I can multiply the number of weeks by the weekly budget amount.
Here's a practical example:
If I choose Jan, Feb, Mar, Apr then the number of weeks should be 17 weeks. And the budget amount should be $17,000.
I figured this out in Crystal Reports. Here's the formula I wrote:
local datetimevar startdate:= {?BegMonth};
local numbervar numofWeeks;
While startdate <= {?EndMonth}
Do(
if month(startdate) in [2,5,8,11] then
numofWeeks := numofWeeks + 5
else
numofWeeks := numofWeeks + 4;
startdate := DATEADD("m",1,startdate);
);
numofWeeks
I've tried several approaches with DAX but I got nothing to work.
DAX doesn't exactly do looping. It does aggregations on filtered columns.
If you don't have a Month column, then create a calculated column.
TableName[Month] = MONTH ( TableName[Date] )
Once you have that, adding up weeks can be done with an iterator function.
Weeks =
SUMX (
VALUES ( TableName[Month] ),
IF ( TableName[Month] IN { 2, 5, 8, 11 }, 5, 4 )
)
The VALUES function is a list of unique values in the filter context, so if you selected Jan - Apr, then it would be {1,2,3,4}. Then SUMX iterates ("loops") over those four values and add 5 or 4 depending on the condition specified in the IF function.
I have a requirement to display the current year 2019 (Actual), the previous year 2018 and 2 years ago 2017 sales data to be displayed on one Line chart. Sales data gets generated every Sunday of the week for a total of 52 weeks in a year
Note: Data is sensitive so not in a position to share it on the forum
Report requirement, two drop downs:
Market selection.
Date selection - This date will be each Sunday of a week
Line chart :
x-axis has the date and y-axis has the market. now when any week drop down is selected (eg: 31st March 2019 then there should be three trend lines in the line chart)
First trend line should display details from April 2019 to March 2020
Second trend line should display details from April 2018 to March 2019
Third trend line should display details from April 2017 to March 2018
Next challenge is I am unable to achieve 2nd and 3rd trend line for previous year and 2 years ago which should be overlapping each other so, total of three trend lines in one line chart.
Another challenge I am facing is dates are not continuous across years (Eg: Jan 2018 Sunday date was 7 and Jan 2019 Sunday date was 6).
Please let me know if any additional information is required.
The image below is how I want my line chart to look like. Instead of months I want date to display:
I have written a DAX which helps in displaying 1 year date range when a drop down is selected.
I want my line chart to display total three trend lines for current year,previous year and 2 years ago.
I have tried year functions to get previous year data but it does not overlap on my current trend line due to difference in date.
Does it have to have date resolution on the x-axis, if not you can use ISO-weeknumber as the x-axis and the year (or FY) as the explanation the line graph.
In your calendar table add this calculated column:
ISOweek = WEEKNUM([date]; 21)
If you need date resolution you can add two calculated columns; date+1year, and date+2years.
Add 364 days if day of the week is the important match or add 365 if date is.
Add two new relationships from your calendar to your data table, one to date+1year and one to date+2years. these will become passive (dashed lines).
Then use the following pattern:
A_measure =
MAXX(
DISTINCT(Calendar);
CALCULATE(
SUM(Table[Data]);
USERELATIONSHIP(Table[date+1year]; Calendar[Date])
// this uses the passive relationship instead of the active
)
)
An then a second measure in the same way but for the third relationship.
In the line diagram use the Calendar[Date] as x-axis and then all three years will overlay.
I am using DAX in Power BI to calculate Previous Month sales total to date to create a KPI visual. i.e. if today is 7th Dec then I want to get sales total from 1st Nov to 7th Nov and compare with current month to date.
CurrentMTD = TOTALMTD(SUM(SALES_VOUCHERS[SaleValue]),DatesTable[Date])
This works fine.
However Previous Month YTD gives me total for entire month of November. I have tried the following so far
PMYTD = totalmtd(sum(SALES_VOUCHERS[SaleValue]),dateadd(DATESMTD(DatesTable[Date]),-1,month))
and
PMYTD = CALCULATE(sum(SALES_VOUCHERS[SaleValue]),
DATESBETWEEN(DatesTable[Date],
FIRSTDATE(PREVIOUSMONTH(DatesTable[Date])),
LASTDATE(DATEADD(DatesTable[Date],-1,MONTH))))
Both return the same answer which is total for the entire previous month .
If I simply hardcode the start and end date in datesbetween version above, then I do get the desired result. But that is not the solution.
I have linked the fact table (Sales_VOUCHERS) to a DatesTable and as of now there are no other visuals on the report page.
Kindly assist what I am missing out on and how I can get Previous Month year to date total
If you're aggregating at the month level (i.e. you're looking at December 2016 vs. November 2016), then the measure you have above will show you the entire month of December compared to the entire month of November (and since December is a partial month and November isn't, it causes the mismatch you see).
If you filter to the current date (e.g. 7th Dec), then both your MTD and Prior Month MTD measures will only show you through the 7th of their corresponding months.
Assuming you don't want to filter to the day level (not unreasonable), you could enhance your formula to filter out future dates. For example:
PMYTD = totalmtd(
sum(SALES_VOUCHERS[SaleValue]),
dateadd(
FILTER(
DATESMTD(DatesTable[Date]),
DatesTable[Date]<TODAY()
),
-1,
month
)
)
This says, if the date is after today, don't pass it into the TOTALMTD calculation (so it will only calculate the first 7 days of the month, for example, if today is Dec 8th - even if you're looking at full months on your report).
Side note: you can also write your previous month measure to re-use your MTD measure rather than redefining it. In this way, if you ever change the MTD calculation, the previous MTD calculation automatically updates.
PMYTD = CALCULATE(
[CurrentMTD],
DATEADD(
FILTER(
DatesTable[Date],
DatesTable[Date]<TODAY()
),
-1,
MONTH
)
)
Useful Resources:
https://www.powerpivotpro.com/2016/01/year-to-date-in-previousprior-year/ (article that covers this problem and a variety of solutions)
https://community.powerbi.com/t5/Desktop/Compare-MTD-with-previous-period/td-p/24656 (forum discussion about the same problem)
http://community.powerbi.com/t5/Desktop/Time-Intelligence-TOTALMTD-vs-DATESMTD-vs-DATEADD/td-p/10088 (forum discussion about DATESMTD vs TOTALMTD)
I'm currently struggling with following request in PowerBI:
I have two CSV files as PowerBI queries, one which defines fiscal months, and another one which lists all subscriptions including start and end date:
Fiscal month CSV:
Month Fiscal Start Fiscal End
January 03.01.2016 04.02.2016
February 05.02.2016 03.03.2016
March 04.03.2016 06.04.2016
April 07.04.2016 02.05.2016
May 03.05.2016 06.06.2016
June 07.06.2016 03.07.2016
July 04.07.2016 05.08.2016
August 06.08.2016 02.09.2016
Subscription CSV:
Account-ID Subscription-Start Subscription-End Item Count
101 08.01.2016 07.02.2016 5
102 15.01.2016 14.03.2016 3
103 05.01.2016 04.06.2016 10
101 08.02.2016 07.03.2016 3
104 10.04.2016 09.05.2016 5
105 16.04.2016 15.07.2016 2
My challenge now is to drill down all subscription item counts per fiscal month as a powerBI table.
Note: an Item Count is valid for a fiscal month if its Subscription-Start < Fiscal End and its Subscription-End > Fiscal End. (Example: A subscription from 15.01.2016 - 14.02.2016 should be counted in january, but not in february)
PowerBI table (schematical example):
Month Item Count
January 18
February 16
March 10
April 17
May 12
June 2
July 0
August 0
How can I implement this report in PowerBI?
THX in advance for your help and BR
bdriven
I've found following solution for my problem:
First I've created a new Table and made a crossjoin of the two queries. Then I've filtered for the lines, where my Subscription Start was before the Fiscal Month End and Subscription End was after the Fiscal Month End.
Based on this new table I can create all respective reports.
Example Code see below:
Fiscal Month Report =
FILTER(
CROSSJOIN(
ALL('Fiscal_month');
ALL('Subscription')
);
('Subscription'[Subscription-Start] < 'Fiscal_month'[Fiscal End] && 'Subscription'[Subscription-End] > 'Fiscal_month'[Fiscal End])
)