Code Generator | DAX

DAX calculateMonthlyTotal Function

This DAX function calculates the monthly total amount by summing weekly totals for each month based on a specified table and date column.


Empty image or helper icon

Prompt

sums the column weekly total amount for each month where the date column is called reporting week

Answer

/*
Function: calculateMonthlyTotal
Purpose: Sums the weekly total amount for each month from a given table where the date column is called reporting week
Parameters: 
1. table - The table containing the weekly total amount and reporting week column
2. reportingWeekColumn - The name of the date column in the table
Return Type: Table
Exceptions: None
*/

calculateMonthlyTotal = 
SUMMARIZE(
    table,
    YEAR(table[reportingWeekColumn]),
    MONTH(table[reportingWeekColumn]),
    "Monthly Total", SUM(table[WeeklyTotalAmount])
)

Usage Example:

Suppose we have a table named 'Sales' with columns 'ReportingWeek' and 'WeeklyTotalAmount'. We can utilize the calculateMonthlyTotal function to sum the weekly total amount for each month as follows:

MonthlyTotal = calculateMonthlyTotal(Sales, "ReportingWeek")

This function will create a new table showing the monthly total amount for each month based on the weekly total amount in the 'Sales' table.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This DAX function calculates the monthly total amount by summing weekly totals for each month based on a specified table and date column.