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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
MartinDra
Frequent Visitor

How to show total sales using date table in periods from date

I have a request to show data in 3 month periods, 

there will be sale that started in 2016 but closed in 2022, so we need to show this as 72 months, 

this will be calculated with each year starting from q1 = 3 Months, q2 = 6 Months, q3 = 9 Months and so on,.

 

E.g

MartinDra_0-1669288830389.png

How can this be done using dax ?

or is it better to go to sql to calculate this? 

 

1 ACCEPTED SOLUTION
v-yinliw-msft
Community Support
Community Support

Hi @MartinDra .

 

You can try this method:

I create two sample tables in two years, Period table and Sales table.

Then we need to calculate the year and the quarter:

New columns:

Year = YEAR('Sales'[Date])
Quar = QUARTER('Sales'[Date])

Then 

Var = 'Sales'[Year] - MIN('Sales'[Year])
Index = 'Sales'[Var] * 4 + Sales[Quar] 
SUMEVERYQ =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        'Sales',
        'Sales'[Year] = EARLIER ( Sales[Year] )
            && 'Sales'[Quar] = EARLIER ( Sales[Quar] )
    )
)

For the period table,

New a column:

M = MID('Period'[Period],1,2) / 3

The M column need to change to the whole number format.

The result column is :

Result =
CALCULATE (
    AVERAGE ( Sales[SUMEVERYQ] ),
    FILTER ( 'Sales', 'Sales'[Index] = 'Period'[M] )
)

vyinliwmsft_2-1669344697485.png

 

Hope these help you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

 

 

View solution in original post

2 REPLIES 2
MartinDra
Frequent Visitor

Hi, 

 

thanks. I think its close but not exactly what I need. 

I need an ability to show year as well.

MartinDra_0-1675182021376.png

so we can see progression over time, 

if I just have the period it only we are limited with the number of months since begining. 

So in Data Warehouse side it isnt going to work. 

 

Any ideas on how to achieve the above?

v-yinliw-msft
Community Support
Community Support

Hi @MartinDra .

 

You can try this method:

I create two sample tables in two years, Period table and Sales table.

Then we need to calculate the year and the quarter:

New columns:

Year = YEAR('Sales'[Date])
Quar = QUARTER('Sales'[Date])

Then 

Var = 'Sales'[Year] - MIN('Sales'[Year])
Index = 'Sales'[Var] * 4 + Sales[Quar] 
SUMEVERYQ =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        'Sales',
        'Sales'[Year] = EARLIER ( Sales[Year] )
            && 'Sales'[Quar] = EARLIER ( Sales[Quar] )
    )
)

For the period table,

New a column:

M = MID('Period'[Period],1,2) / 3

The M column need to change to the whole number format.

The result column is :

Result =
CALCULATE (
    AVERAGE ( Sales[SUMEVERYQ] ),
    FILTER ( 'Sales', 'Sales'[Index] = 'Period'[M] )
)

vyinliwmsft_2-1669344697485.png

 

Hope these help you.

Here is my PBIX file.

 

Best Regards,

Community Support Team _Yinliw

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

 

 

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors