Reply
tomashavlicek
New Member

Periodicity based calculation (measure) in PowerBI

Hi I have to datasets:

  1. Calendar of future dates for the next 2 years
  2. Active subscriptions database with the following clolumns: Subcription_ID, Product_Name, Period_in_Months and Valid_From_Date

So each subsription has a starting date (Valid_From_Date) and based on period (e.g. 2 months) the product will ship as follows:

1st shipment on Valid_From_Date, 2nd shipment on Valid_From_Date + (1 * 2 months), 3rd shipment on Valid_From_Date + (2 * 2 months), 4th shipment on Valid_From_Date + (3 * 2 months), etc.

 

What I would like to do is a Measure, that would caluclate the number of shipments scheduled for each date in the calendar based on this dataset so I can plot she upcoming shipments for example like this:

tomashavlicek_0-1709378076514.png

I think the trick is in calculating the number of days between the given date and the Valid From date and dividing the result by periodicity in days. If the result of the division is whole number, the shipment is scheduled on that date.

 

Have you ever tried bulding a mesure like this? I wanted a simple solution instead of building new datasets with 100 of upcoming shipment days for thousands of customers.

 

Many thanks,

Tomas.

 

 

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @tomashavlicek ,

 

My sample:

vrzhoumsft_0-1709538507863.png

Calendar =
ADDCOLUMNS (
    CALENDAR ( EOMONTH ( TODAY (), -1 ) + 1, EOMONTH ( TODAY (), 24 ) ),
    "Year", YEAR ( [Date] ),
    "Month", FORMAT ( [Date], "MMM" ),
    "MonthSort", MONTH ( [Date] )
)

Measure:

Measure = 
VAR _DATEDIFF = DATEDIFF(MAX('Table'[Valid_From_Date]),MAX('Calendar'[Date]),MONTH)
VAR _MOD = MOD(_DATEDIFF,SUM('Table'[Month Interval]))
RETURN
CALCULATE(SUM('Table'[Quantity]),FILTER('Table',_DATEDIFF>=0 && _MOD = 0))

Result is as below.

vrzhoumsft_1-1709538671494.png

 

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.

 

 

Hi, thank you very much for the quick reply. I tried the solution but struggle to implement it.

I have:
- created a new calendar based on your suggenstion
- created a new Measure (Quantity MOD) in my table of subsciptions (BC_Subscriptions)
- created a blank page with a new visual to plot this
 
However the output look like this (dates are fine but there is data only in the first month correponding to the total amount of subcriptions in the table:
tomashavlicek_0-1709548936736.png

The measue:

tomashavlicek_1-1709549036104.png

 

The BC Subscriptions table:

tomashavlicek_3-1709549443673.png

 

Calendar table:

tomashavlicek_4-1709549508303.png

 

Any relations I should make between the tables?

 

Thank you very much.

Tomas.


 

 

 

avatar user

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)