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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
mds123
Frequent Visitor

Can I make a custom function like DatesYTD and DatesMTD ?

My data needs to be reported at a period level and a period is roughly 28 days, but not always. I need to report the cumulative sales at the day level for each period. The dax functions DATESMTD and DATESYTD are able to provide a cumulative sales at the month and year level. Are there any ways I could do this at the period level? Am I able to see the underlying code for those functions and make my own?

 

I can use calculate([Total Sales], DATESMTD(Dates[Date])) to get the cumulative sales for the month, but I need to get it at the period level.

 

My dates table is designed below. 

Date | Period | Fiscal Year

2 REPLIES 2
mh2587
Super User
Super User

First Create date period table like following:
| PeriodID | StartDate   | EndDate     |
|----------|-------------|-------------|
| 1        | 2024-01-01  | 2024-01-28  |
| 2        | 2024-01-29  | 2024-02-25  |
| 3        | 2024-02-26  | 2024-03-24  |
| ...      | ...         | ...         |

//And then use this measure 

CumulativeSalesPeriod = 
CALCULATE(
    SUM('YourTable'[Total Sales]),
    FILTER(
        ALL('YourTable'[Date]),
        'YourTable'[Date] <= MAX('YourTable'[Date]) &&
        'YourTable'[Date] >= MIN('YourTable'[Date]) &&
        'YourTable'[Date] >= RELATED('PeriodTable'[StartDate]) &&
        'YourTable'[Date] <= RELATED('PeriodTable'[EndDate])
    )
)

Did I answer your question? If so, please mark my post as a solution!


Proud to be a Super User!




LinkedIn Icon
Muhammad Hasnain



Greg_Deckler
Super User
Super User

@mds123 You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.