Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

Date table in a Power BI report

Hi,

 

I have a table as below:

 

data_DateIntramonthAttributeValue
31/01/202031-Jan-20KIDS20%
31/01/202031-Jan-20TEACHERS30%
31/01/202031-Jan-20Admin Staff40%
28/02/202028-Feb-20KIDS0.00%
28/02/202028-Feb-20TEACHERS100%
28/02/202028-Feb-20Admin Staff23%
31/03/202031/03/2020KIDS40%
31/03/202031/03/2020TEACHERS23%
31/03/202031/03/2020Admin Staff45%
30/04/202030/04/2020KIDS23%
30/04/202030/04/2020TEACHERS67%
30/04/202030/04/2020Admin Staff70%
29/05/202029/05/2020KIDS56%
29/05/202029/05/2020TEACHERS98%
29/05/202029/05/2020Admin Staff35%
30/06/202030/06/2020KIDS56%
30/06/202030/06/2020TEACHERS34%
30/06/202030/06/2020Admin Staff56%
31/07/202031/07/2020KIDS67%
31/07/202031/07/2020TEACHERS23%
31/07/202031/07/2020Admin Staff45%

 

My final output needs to have a datepicker which has all distinct dates. Based onn the date selected, it needs to display data for previous 4 months: In the screenshot below, I've selected 31/07/2020 in the date picker, so I get output for the previous 3 months. The selected date is displayed as intra-month

 

 
     
 Intra-Month30/06/202029/05/202030/04/2020
Kids67%56%56%23%

 

If I select, 29/05/2020, I get the following results in the Kids table:

 Intra-Month30/04/202031/03/202028-Feb-20
Kids56%23%40%0%

 

 

I've created a Date table to map the selected date to previous months using the Power BI query below:

Table = ADDCOLUMNS(CALENDARAUTO(),"MONTH",MONTH([Date]),"Year",YEAR([Date]),"Last working day",EOMONTH([Date],0)-if(WEEKDAY(EOMONTH([Date],0),2)<=5,0,if(WEEKDAY(EOMONTH([Date],0),2)=6,1,2)),"PREV",EOMONTH(([Date]),1)-if(WEEKDAY(EOMONTH([Date],1),2)<=5,0,if(WEEKDAY(EOMONTH([Date],1),2)=6,1,2)),"PREV MONTH",EOMONTH(([Date]),2)-if(WEEKDAY(EOMONTH([Date],2),2)<=5,0,if(WEEKDAY(EOMONTH([Date],2),2)=6,1,2)),"PREV MONTH2",EOMONTH(([Date]),3)-if(WEEKDAY(EOMONTH([Date],3),2)<=5,0,if(WEEKDAY(EOMONTH([Date],3),2)=6,1,2)))
 
I cant get the 2 tables to connect to display dates as column headers and values as shown in the desired output.
 
Any help is greatly appreciated.
 
 
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I use your to table and build a measure to achieve your goal.

Build a silcer by Last working day column in Date Table, then build a measure.

Measure = 
VAR _selectedcolumn =
    SELECTEDVALUE ( Table2[Last working day] )
VAR _Datediff =
    DATEDIFF ( MAX ( 'Table1'[data_Date] ), _selectedcolumn, MONTH )
RETURN
    IF (
        _Datediff >= 0
            && _Datediff < 4,
        CALCULATE ( SUM ( 'Table1'[Value] ) ),
        BLANK ()
    )

Build a matrix visual as below:

1.png

Result:

Select 2020/07/31

2.png

Select 2020/05/29

3.png

You can download the pbix file from this link: Date table in a Power BI report

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

 

View solution in original post

3 REPLIES 3
v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

I use your to table and build a measure to achieve your goal.

Build a silcer by Last working day column in Date Table, then build a measure.

Measure = 
VAR _selectedcolumn =
    SELECTEDVALUE ( Table2[Last working day] )
VAR _Datediff =
    DATEDIFF ( MAX ( 'Table1'[data_Date] ), _selectedcolumn, MONTH )
RETURN
    IF (
        _Datediff >= 0
            && _Datediff < 4,
        CALCULATE ( SUM ( 'Table1'[Value] ) ),
        BLANK ()
    )

Build a matrix visual as below:

1.png

Result:

Select 2020/07/31

2.png

Select 2020/05/29

3.png

You can download the pbix file from this link: Date table in a Power BI report

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

 

amitchandak
Super User
Super User

@Anonymous , if select 1 date or set of date but want more data then that refer

https://www.youtube.com/watch?v=duMSovyosXE

 

if you simply want rolling you can use with date table

Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],ENDOFMONTH(Sales[Sales Date]),-3,MONTH))
Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date]),-3,MONTH))
Rolling 3 = CALCULATE(sum(Sales[Sales Amount]),DATESINPERIOD('Date'[Date],startofmonth(Sales[Sales Date]),-3,MONTH))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi
https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

See if my webinar on Time Intelligence can help: https://community.powerbi.com/t5/Webinars-and-Video-Gallery/PowerBI-Time-Intelligence-Calendar-WTD-YTD-LYTD-Week-Over-Week/m-p/1051626#M184


Appreciate your Kudos.

 

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.