Using the built-in Power BI date table, you are able to drill down from year -> Qtr -> month effortlessly, as shown below:
The date table used to generate the drill-down figure above:
DAX Formula: Cal = CALENDAR(MIN(Data[Date]),MAX(Data[Date]))
I would like to maintain this drill-down capability for the following custom date table:
Dates =
GENERATE (
CALENDAR ( DATE ( 2016, 10, 1 ), DATE ( 2025, 10, 1 ) ),
VAR currentDay = [Date]
VAR year =
IF ( MONTH ( currentDay ) >= 10, YEAR ( currentDay ) + 1, YEAR ( currentDay ) )
VAR quarter =
IF (
MONTH ( currentDay ) >= 10,
1,
IF ( MONTH ( currentDay ) <= 3, 2, IF ( MONTH ( currentDay ) <= 6, 3, 4 ) )
)
VAR month =
IF (
MONTH ( currentDay ) >= 10,
MONTH ( currentDay ) - 9,
MONTH ( currentDay ) + 3
)
RETURN
ROW ( "year", year, "quarter", quarter, "month", month )
)
It seems that the moment I mark "Dates" as the date table, I am unable to implement the built-in drill-down capability. I tried adding a date hierarchy, but cannot seem to control the order of the drill-down. For example, the visuals display month initially, and then "drill-down" to year, and finally to quarter. (this order doesn't make sense to me and I can't seem to change it). I need to be able to go from year -> quarter -> month, as before. I cannot use the default date table because I am using fiscal dates.
This is the result I am getting:
Please let me know if anything needs clarification, thank you!
I am able to sort in custom date table(with different fiscal year), Please find the snapshot attached for your reference.
I have used the power query to create a custom date table ( you can find the code here https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-2-fiscal-columns)
we just need to change the startdate, enddate and StartOfFiscalYear(custom fiscal month).
Try and let me know
You have defined your date hierarchy as Date > year > month > quarter, per your screenshot. The order of the fields in the hierarchy defines your drill order. You do not need to define a hierarchy, you can simply drop fields ad-hoc into the field well for any visual. But if you're using a hierarchy, you must define it in the correct order:
year > quarter > month > Date
You can see the order in your hierarchy:
You can reorder these fields by clicking and dragging them within the hierarchy, or by right clicking and selecting "Move up" or "Move down":
Related
I'm trying to calculate MAT (Moving Annual Total) using DAX, but can't realize exactly what I want.
I have the data as below.
What I'm trying to is calculate the total of treatment for each 12 month, like "Jan 21 - Dec 21" which has 'date' from 2020/1/1 to 2020/12/1. i.e. 'A' appears 4 times in that period, so the result will be like below.
Then I'd like to continue this for each latest 12 months, and finally visualize it like below.
I've read that I should use CALCULATE and DATESPERIOD in DAX, can't calculate exactly though. The following code is the one I tried and failed.
Moving Annual Total = CALCULATE(
COUNTA('2017-2022Q1'[idnum]),
DATESINPERIOD('2017-2022Q1'[mat].[Date], LASTDATE('2017-2022Q1'[mat].[Date]), 12, MONTH))
Could someone kindly give me an advise to realize this?
Thanks.
*This is the sample file.
https://drive.google.com/file/d/1gDNeBe5KiKBqx3cZ7G0SMiSQ23w96NF4/view?usp=sharing
In your dax measure, I recommend you first to create a date table and create a one-to-many relationship with the fact table(your table: '2017-2022Q1') ; then filter the date table in your calculate measure, not the fact table('2017-2022Q1') directly as you did here. You should follow the best practice.
For Example: How to create a date table using dax:
Date =
VAR MinYear = YEAR ( MIN ( '2017-2022Q1'[date] ) )
VAR MaxYear = YEAR ( MAX ( '2017-2022Q1'[date] ) )
RETURN
ADDCOLUMNS (
FILTER (
CALENDARAUTO( ),
AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )
),
"Calendar Year", "CY " & YEAR ( [Date] ),
"Month Name", FORMAT ( [Date], "mmmm" ),
"Month Number", MONTH ( [Date] )
)
Your final code could be like this:
Moving Annual Total = CALCULATE(
COUNTA('2017-2022Q1'[idnum]),
DATESINPERIOD('Date'[Date], LASTDATE('Date'[Date]), -12, MONTH)
)
if you define the start date using the lastdate() function, then It returns the last date in your filter context. you should also specify the interval as (-12) month to extract all dates within 1 year period.
Hope It helps.
I need some help with a filter.
The filter needs to filter date between the 16th of one month and the 15th of the next month, this should be for the previous months when looking at the data so if you look at it on March it will show data between 16th of Jan to 15th of Feb.
The data is 'Duration' of days which i will total up for the between 16th-15th period.
I have a measure for this but I'm not sure how it would go into my table visual to show the right data:
Assessment Date =
IF (
DAY ( TODAY () ) < 16,
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ) - 1, 15 ),
DATE ( YEAR ( TODAY () ), MONTH ( TODAY () ), 15 )
)
Is there a way I can put this measure into a new formula and do it like that? or is there another formula i could use?
You could use variables and try something like this:
Duration =
VAR Start1 =
DATE(
IF(MONTH(TODAY())<=2,YEAR(TODAY())-1,YEAR(TODAY())),
IF(MONTH(TODAY())=1,11,IF(MONTH(TODAY())=2,12,MONTH(TODAY())-1)),
16)
VAR End1 =
DATE(
IF(MONTH(TODAY())=1,YEAR(TODAY())-1,YEAR(TODAY())),
IF(MONTH(TODAY())=1,12,MONTH(TODAY())-1),
15)
VAR Calc =
IF(Table[Date]>=Start1 && Table[Date]<=End1,Table[Duration],0)
RETURN Calc
This would return values for only those rows which fall into the date filter. I am not sure if I got your date filter condition correctly. Either way, you should be able to adjust the calculation to get your desired results. Hope this helps.
I have a report page which contains tables about cars and bikes. Each of them is a separate table like:
Cars
Id | CarName | Time1
Bikes
Id | BikeName | Time2
There are no relationships between these tables however they must be displayed in same page. How can i use a Slicer or a Timeline 2.0.1 to manipulate all dashboards simultaneously by just filtering once the date?
I.e. If i select interval between 01/01/19-02/02/19 it will filter the Cars by field Time1 and the Bikes by Time2 and display the dashboards accordingly?
Thanks so much!
Build a CalendarTable and link both tables bikes and cars to it. You may find lots of propositions of CalendarTables. Then make slicer on CalendarTable. Beware not to make slicer on your fact tables bikes or cars.
There are more advantages to using CalendarTable then just the possibility of filtering multiple tables. I would use CalendarTable even with a single table because it contains complete list of days - your bike table may not - and that is why time intelligence functions work properly. And mind the performance - slicing small and unique CalendarTable is faster then big fact tables.
Here is an example of simple CalendarTable. Choose in menu Modeling / New Table:
Calendar =
GENERATE (
CALENDAR (
DATE ( 2016, 1, 1 ),
DATE ( 2020, 12, 31 )
),
VAR CurrentDay = [Date]
VAR day = DAY ( CurrentDay )
VAR month = MONTH ( CurrentDay )
VAR year = YEAR ( CurrentDay )
VAR YM_text = FORMAT ( [Date], "yyyy-MM" )
RETURN
ROW (
"day" , day,
"month" , month,
"year" , year,
"YM_text" , YM_text
)
)
Set up min and max date. Here from 2016-01-01 to 2020-12-31.
I have a table which contains a list of products scores by date:
From this table, I have to make a plot of the cumulative percentage of each quality by date.
At this moment I have the percentage of each class by day:
For that I used this measurement:
Measure =
CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( Table1, Table1[Date] = MAX ( Table1[Date] ) ),
ALLEXCEPT ( Table1, Table1[Score] )
)
/ CALCULATE (
SUM ( Table1[Percentage_By_Class] ),
FILTER ( ALL ( Table1 ), Table1[Date] = MAX ( Table1[Date] ) )
)
But this only considers the percentage of each day. I need to consider all previous dates. E.G. for day 2 I need to consider days 1 and 2, for day 3 I need to consider days 1,2,3 and so on.
How can I accomplish this?
in my opinion, you need a calendar for the date first, you can create a table easily bay dax function =CALENDARAUTO() And mark it as a calendar table,
After that, you can use a DATEMTD or a DATEYTD function for your coding purpose.
here are the steps:
1 - https://learn.microsoft.com/en-us/dax/calendarauto-function-dax
select left pane --> table --> modelling / create table and add dax formula
2- reference the table as a date table, right click on the table from the right pane
after then you can use data functions like YTD MTD ,
new measure :
1st mesure : AVG1 = AVG(DATA_)
2nd measure : YTD AVG ALL = CALCULATE([AVG1];DATESYTD(CALENDAR[DATE]))
REF: https://learn.microsoft.com/en-us/dax/dateadd-function-dax
then you can use MONTH(CALENDAR(DATE)) on left and YTD AVG as a value at any table...
regards.
SUNAY
I need several measures in my report. The measure I want to start with is count of distinct ID four months before the month I selected on (e.g if I select on Aug 2018, the calculation would be all distinct ID before 30/04/2018). The reason I'm doing this is later on I also want to use this same slicer to work on count of ID within the four month period based on the selection.
Here is my DAX Calculation with comments:
Count four months ago =
// Find the end date of the month
VAR end_of_last_quarter =
FORMAT ( EOMONTH ( MAX ( 'Calendar'[Date] ), -4 ), "dd/mm/yyyy" )
RETURN
// Count distinct ID on or before that date
CALCULATE (
DISTINCTCOUNT ( 'Report Data'[Id] ),
FORMAT ( 'Report Data'[REPORT DATE], "d/mm/yyyy" )
<= FORMAT ( end_of_last_quarter, "d/mm/yyyy" )
)
& " Reports before "
& end_of_last_quarter
However after checking this calculation, it seems it only gives me the number of counts in the month I selected:
The screenshot tells me there are 12 report in Apr 2018, rather than the right number before 31/12/2017.
Thanks in advance for any ideas