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
anandav
Skilled Sharer
Skilled Sharer

How to calculate monthly totals?

Hi All,

 

I have the following data

Country   Product        Sales     Qty        Sales Date 

AProduct 1100102/01/2018
BProduct 2200202/01/2018
CProduct 3300303/01/2018
DProduct 1400405/01/2018
EProduct 2500507/02/2018
AProduct 16006010/02/2018
BProduct 27007011/02/2018
CProduct 28008012/03/2018
DProduct 28509014/03/2018
DProduct 3100010015/03/2018

 

I want to calucate the total for each month.

Country          Product                 Sales                     Qty               Sales Date       Month Sales

AProduct 1100102/01/2018 
BProduct 2200202/01/2018 
CProduct 3300303/01/2018 
DProduct 1400405/01/20181000
EProduct 2500507/02/2018 
AProduct 16006010/02/2018 
BProduct 27007011/02/20181800
CProduct 28008012/03/2018 
DProduct 28509014/03/2018 
DProduct 3100010015/03/20182650

 

Any help would be appreciated.

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Right click on Calendar Date, new hierarchy, I suppose this will solve your problem.

 

Then you should have year, quarter, month and day available.

View solution in original post

v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @anandav,

 

As  @Anonymous mentioned, you could create a table with Date hierarchy like below then you could get Month total sales.

 

Capture.PNG

 

In addition, you could create a calculated column with the formula below.

 

Sales per month =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        'Sales',
        MONTH ( 'Sales'[Sales Date] ) = MONTH ( EARLIER ( 'Sales'[Sales Date] ) )
    )
)

Then you could get your expected output.

 

Month total.PNG

 

For reference, you could have a look at this similar thread.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
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

7 REPLIES 7
Anonymous
Not applicable

Hi. I have a similar situation and I want the result as the other user.  I tried the bellow options but none worked.

 

I want to calculate Each Employees Monthly Working Hours - therefore by employe and month-year.

I am using below formula: 

 

Total Hourse per month = CALCULATE(sum(working hours]);FILTER('workers table'; 'workers table'[Date].[Date] && FILTER('workers table'; 'workers table'[name and surname]))) 
 
getting below error 
 
The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
 
Can anyone help? 
Thanks a lot!!
v-piga-msft
Resident Rockstar
Resident Rockstar

Hi @anandav,

 

As  @Anonymous mentioned, you could create a table with Date hierarchy like below then you could get Month total sales.

 

Capture.PNG

 

In addition, you could create a calculated column with the formula below.

 

Sales per month =
CALCULATE (
    SUM ( Sales[Sales] ),
    FILTER (
        'Sales',
        MONTH ( 'Sales'[Sales Date] ) = MONTH ( EARLIER ( 'Sales'[Sales Date] ) )
    )
)

Then you could get your expected output.

 

Month total.PNG

 

For reference, you could have a look at this similar thread.

 

Best Regards,

Cherry

Community Support Team _ Cherry Gao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous
Not applicable

@v-piga-msft

 

Hi!

 

Could you just explain what the EARLIER does here? I'm a bit confused by that function TBH.

 

Thanks!

Hi @Anonymous,

Check this article. It may help you and also explain how you can use variables to avoid using EARLIER.

https://www.sqlbi.com/articles/variables-in-dax/

 

Anonymous
Not applicable

Do you have a Calendar Table? On the field list, do you see any "Date Hierarchy"?

@Anonymous,

Yes, I have a calendar table and relationsip established with Sales Date in Sales table.

No, I cannot see the date hierarchy.

 

Anonymous
Not applicable

Right click on Calendar Date, new hierarchy, I suppose this will solve your problem.

 

Then you should have year, quarter, month and day available.

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.