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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
xmarkx
Frequent Visitor

Split values equally into years or months or weeks using Field parameters

Hello there BI community!

First time poster here with serious imposter syndrome (pun intended).
I got a database with Transactions table in it. I imported the table to Power BI and I also created a Data table with Year, Month, Week and Day columns (among others), but did not make a relation between the two tables.

Here is a simplified example of the table:
Sample dataSample data
My goal is to show the Price equally distributed into Year, Month, Week or even Day based on Fields parameters.

I have found a solution that is really close to what I want, but this solution divides up the Price not equally (that is, not in a uniform fashion), but as I understand, it takes the days and rolls them up based on the amount of days in the desired periods.
This results in fluctuating Price values, where February will have lower Price because it has fewer days, and longer months have higher Price.

Here is the DAX code for the example I mentioned above, plus the results I am getting.

Price Distribution = SUMX(
    VALUES('Date'[Date]),
    CALCULATE(
        SUMX(
            FILTER(
                Transactions,
                Transactions[PeriodFrom] <= MAX('Date'[Date]) && Transactions[PeriodTo] >= MIN('Date'[Date])
                ),
                DIVIDE(Transactions[Price],
                DATEDIFF(Transactions[PeriodFrom], Transactions[PeriodTo], DAY)+1
                )
            )
        )
    )

The results using Field parameters on Year, Month and Week level →
Yearly distribution:
Year distributionYear distribution

Monthly distribution:
Month distributionMonth distribution

Month distribution for the Year 2022 only:
Month distribution 2022Month distribution 2022

Weekly distribution only in 2022:

Week distribution 2022Week distribution 2022

The desired outputs should look like this (week output is not here, but I hope the logic is clear) →

Yearly distribution:
Year distribution desired outputYear distribution desired output

Monthly distribution for Year 2022:
Month distribution 2022 desired outputMonth distribution 2022 desired output

If You need more information or have any questions, please don't hesitate to ask.
Thank you in advance community and have a lovely day!

2 REPLIES 2
xmarkx
Frequent Visitor

@tharunkumarRTK 
Do you mean that this 13 period division would solve the weekly distribution problem?
I don't yet see how this method would solve the monthly distribution problem.
As I see it now, your proposed solution would require that I create a separate measure for the Year / Month level, and another one for the week level.
In that case I don't know how I could have the Field parameters applied as shown in the example in my OP.

Could you elaborate on your proposal?

tharunkumarRTK
Super User
Super User

@xmarkx 
I think for your requirement, you should consider using a different logic other than Months. You can divide a year into 13 periods, then each period will have 28 days. This way you will be able to distribute your prices equally. 


If the post helps please give a thumbs up


If it solves your issue, please accept it as the solution to help the other members find it more quickly.


Tharun





Helpful resources

Announcements
OCT PBI Update Carousel

Power BI Monthly Update - October 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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