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
Anonymous
Not applicable

Show 13 months for a chosen year in a diagram

I am counting the number of vehicles at the end of each month.

 

In my DimDate table I have (among other columns) Year (text), Year Month (text) and Date (Date) and OnlyLastDayofMonth (ABC/123) with only the last date of each month in it.

 

Each vehicle is included in all dates in a range from start date to end date.

 

My measure:

Vehicle Count end of month = calculate( DISTINCTCOUNT('TestObject/Transactions'[test_object_id]),DimDate[OnlyLastDayofMonth]<>"")
 
I need to have the total per the last day of December as my opening balance for every selected year.
 
So when I choose the year 2021, I want to see Dec 2020-Dec 2021. At the moment I am abviously only getting Jan-Dec.
 
Goaanna_0-1649361678052.png

 

 

 How can I get 12 months + the last month of the preceeding year as the first visible month? I.e. 13 months instead of 12?

Thanks, Anna.

1 ACCEPTED SOLUTION

Hi @Anonymous 

Thanks for your reply. 

The reason for the error is because you use the year from dimdate as the slicer, so the visual will be filtered.

(1) In this scenario, you need to create a year table for slicer, 

vxiaotang_0-1651128372609.png

(2) then try this, create the measure below,

 

Vehicle Count end of month = 
VAR _End =
    DATE ( SELECTEDVALUE(YearSlicer[Year]), 12, 31 )
VAR _start =
    EOMONTH ( _End, -13 )
return IF(MIN(DimDate[Date])<_End,
     CALCULATE (
        DISTINCTCOUNT ( 'TestObject/Transactions'[test_object_id] ),
        FILTER (
            'TestObject/Transactions',
            'TestObject/Transactions'[date] > _start
                && 'TestObject/Transactions'[date] < EOMONTH( MIN(DimDate[Date]),0)
        )
    ) ,BLANK())

 

then it returns the distinctcount of [test_object_id] at the end of each month

vxiaotang_0-1652166572425.png

Best Regards,

Community Support Team _Tang

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

View solution in original post

5 REPLIES 5
v-xiaotang
Community Support
Community Support

Hi @Anonymous 

Please try this measure

Vehicle Count end of month =
VAR _End =
    DATE ( MIN ( 'DimDate'[Year] ), 12, 31 )
VAR _start =
    EOMONTH ( _End, -13 )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( 'TestObject/Transactions'[test_object_id] ),
        FILTER (
            'TestObject/Transactions',
            'TestObject/Transactions'[date] > _start
                && 'TestObject/Transactions'[date] <= _End
        )
    )

Best Regards,

Community Support Team _Tang

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

Anonymous
Not applicable

Thank you! Brilliant thinking! @v-xiaotang 

The thing is, I am counting vehicled that exist beteen dates (Delivery date and end date). So I have an interval table and then I count the vehices at the end of each month.

 

Whe I used yoyr brilliant measure (changed a bit):

Community Vehicle Count end of month =
VAR _End =
DATE ( MIN ( 'DimDate'[Year] ), 12, 31 )
VAR _start =
EOMONTH ( _End, -13 )
RETURN
CALCULATE (
DISTINCTCOUNT ( 'TestObject/Transactions'[test_object_id] ),
FILTER (
'DimDate',
'DimDate'[OnlyLastDayofMonth] > _start &&
'DimDate'[OnlyLastDayofMonth] <= _End
)
)
 
I still have the problem that when I filter per year, I am only getting the count for that year.  I would for example like to include YearMonth 202112 when I filter per year 2022...
 
Goaanna_0-1649845526321.png

 

 
 

Hi @Anonymous 

Thanks for your reply. 

The reason for the error is because you use the year from dimdate as the slicer, so the visual will be filtered.

(1) In this scenario, you need to create a year table for slicer, 

vxiaotang_0-1651128372609.png

(2) then try this, create the measure below,

 

Vehicle Count end of month = 
VAR _End =
    DATE ( SELECTEDVALUE(YearSlicer[Year]), 12, 31 )
VAR _start =
    EOMONTH ( _End, -13 )
return IF(MIN(DimDate[Date])<_End,
     CALCULATE (
        DISTINCTCOUNT ( 'TestObject/Transactions'[test_object_id] ),
        FILTER (
            'TestObject/Transactions',
            'TestObject/Transactions'[date] > _start
                && 'TestObject/Transactions'[date] < EOMONTH( MIN(DimDate[Date]),0)
        )
    ) ,BLANK())

 

then it returns the distinctcount of [test_object_id] at the end of each month

vxiaotang_0-1652166572425.png

Best Regards,

Community Support Team _Tang

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

Ashish_Mathur
Super User
Super User

Hi,

See if my post here helps - Flex a Pivot Table to show data for x months ended a certain user defined month.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

No sorry 😞

 

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.