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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
VipinReddy
Employee
Employee

Previous, current and next month hours calculation

I am facing an issue calculating the hours for the previous, current and next month. The sample data I have is as below. 

VipinReddy_1-1625119677657.png 

Based on the date I would like to calculate the Available, Allocated and Consumed Hours. I would like the result to be in the way below. 

VipinReddy_2-1625119786655.png

Currently my matrix shows the total hours for each. I want to show the previous, current and next month hours for all three i.e. Available, Allocated and Consumed. 

Hope you can help me with this. Thank you in advance. 

1 ACCEPTED SOLUTION
v-xulin-mstf
Community Support
Community Support

Hi @VipinReddy

 

You need create a dimension table as:

Date slicer = 
VALUES('Table'[Date]) 

Try measure as:

Allocate_curr_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        'Table'[Date]=MAX('Date slicer'[Date])))
Allocate_next_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        MONTH('Table'[Date])=MONTH(MAX('Date slicer'[Date]))-1)
)
Allocate_pre_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        MONTH('Table'[Date])=MONTH(MAX('Date slicer'[Date]))+1)
)

Here is the output:

vxulinmstf_0-1625559538445.png

The pbix is attached.

 

If you still have some question, please don't hesitate to let me known.‌‌

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

View solution in original post

2 REPLIES 2
v-xulin-mstf
Community Support
Community Support

Hi @VipinReddy

 

You need create a dimension table as:

Date slicer = 
VALUES('Table'[Date]) 

Try measure as:

Allocate_curr_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        'Table'[Date]=MAX('Date slicer'[Date])))
Allocate_next_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        MONTH('Table'[Date])=MONTH(MAX('Date slicer'[Date]))-1)
)
Allocate_pre_month = 
CALCULATE(
    MAX('Table'[Allocate]),
    FILTER(
        'Table',
        MONTH('Table'[Date])=MONTH(MAX('Date slicer'[Date]))+1)
)

Here is the output:

vxulinmstf_0-1625559538445.png

The pbix is attached.

 

If you still have some question, please don't hesitate to let me known.‌‌

Best Regards,

Link

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution. Really appreciate!

amitchandak
Super User
Super User

@VipinReddy , with help from a date table and time intelligence

 

MTD Sales = CALCULATE(SUM(Table[hour]),DATESMTD('Date'[Date]))
last MTD Sales = CALCULATE(SUM(Table[hour]),DATESMTD(dateadd('Date'[Date],-1,MONTH)))

next MTD Sales = CALCULATE(SUM(Table[hour]),DATESMTD(dateadd('Date'[Date],1,MONTH)))
last month Sales = CALCULATE(SUM(Table[hour]),previousmonth('Date'[Date]))
next month Sales = CALCULATE(SUM(Table[hour]),nextmonth('Date'[Date]))

this month = CALCULATE(Table[hour]),DATESMTD(ENDOFMONTH('Date'[Date])))

 

 

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 :radacad sqlbi My Video Series Appreciate your Kudos.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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