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
AlfredoBIS
Frequent Visitor

Grand total and yearly total are not true

Hi guys,

I want to write dax query that shows  sales on weekdays. But grand total and yearly total are not true. Could you help me for solving this problem?

Best regards.

 

SalesPerWorkingDay = DIVIDE([TotalSales],
SUMX (VALUES ('DimDate'[Datekey].[Year] ),sumx(
VALUES ( 'DimDate'[Datekey].[Month] ),
IF ( [TotalSales] > 0, [WorkingDays] )
)
)
)
salesworkingdays.JPG
17 REPLIES 17
AlfredoBIS
Frequent Visitor

Hi, 

I couldnt solve it yet 😕

Hi, @AlfredoBIS 

Has the problem been solved so far?

If you still need help, please share a sample file for further research.

Best Regards,
Community Support Team _ Eason

 

You can send a picture of your relationship just like I am sending:

rodrigosan_0-1657156266842.png

 

 

rodrigosan
Resolver III
Resolver III

You can send a picture of your relationship just like I am sending:

rodrigosan_0-1657057010061.png

 

rodrigosan
Resolver III
Resolver III

You can share a picture of your relationships.
Based on them I believe we can find a solution.

rodrigosan
Resolver III
Resolver III

See if it helps you
Assuming that your date dimension table is correctly related to your fact table.
And in your dates dimension table you have a column that identifies whether the day is useful or not.
I suggest the steps and measures below:

WorkDays =
CALCULATE(
COUNT('📅dCalendar'[Work Day Value]),
'📅dCalendar'[Work Day Value] = 1)

SalesPerWorkingDay =
DIVIDE([Sales Amount] , [WorkDays])

Thank you so much.

Now

WorkingDays =
SUMX (
'DimDate',
IF ( 'DimDate'[IsWorkDay] = "WorkDay", 1, 0 )
)
But I tried
Workdays2 = CALCULATE(count(DimDate[CalendarYear]),DimDate[IsWorkDay]="WorkDay")
This gave error for this
SalesPerWorkingDay = DIVIDE([TotalSales],
SUMX (VALUES ('DimDate'[Datekey].[Year] ),sumx(
VALUES ( 'DimDate'[Datekey].[Month] ),
IF ( [TotalSales] > 0[WorkingDays] )
)
)
)
 
tamerj1
Super User
Super User

Hi @AlfredoBIS 

try to wrap the inner SUMX with CALCULATE 

Hi,

Thank you so much for your answer. I used calculate but doesnt change result 

 

SalesPerWorkingDay = DIVIDE([TotalSales],
(SUMX (VALUES ('DimDate'[Datekey].[Year] ),calculate(sumx(
VALUES ( 'DimDate'[Datekey].[Month] ),
IF ( [TotalSales] > 0, [WorkingDays] )
)
)
)))
 

@AlfredoBIS 

Better to have year and month columns.then you can iterate over SUMMARIZE ( DimDate, DimDate[Year], DimDate[Month] ). It should work. 

Hi I tried this:  but couldnt solve yearly and grand total problem.

WorkingDays =
SUMX (
'DimDate',
IF ( 'DimDate'[IsWorkDay] = "WorkDay", 1, 0 )
)
 
TotalSales = SUMX ( FactSales, FactSales[SalesQuantity] * FactSales[UnitPrice])
 
SalesPerWorkingDay8 = DIVIDE([TotalSales],
SUMX (VALUES ('DimDate'[CalendarYear] ),sumx(
VALUES ( 'DimDate'[CalendarMonth] ),
IF ( [TotalSales] > 0, [WorkingDays] )
)
)
)
 

AlfredoBIS_0-1657051893764.png

 

I don't understand why you are using SUMX.
your goal is not to know how many working days?
That's why I suggested using COUNT.
You just have a column in your date dimension table that identifies the date as useful or not.

Hi @rodrigosan,

I tried  for calculating workdays like this. But result doesnt change. I want to correct grand total sales and yearly total sales.

Workdays2 = CALCULATE(count(DimDate[CalendarYear]),DimDate[IsWorkDay]="WorkDay")

You can share a picture of your relationships.
Based on them I believe we can find a solution.

Sure,

DimDate Table

AlfredoBIS_0-1657055888940.png

FactSatles table

AlfredoBIS_1-1657055938855.png

relationship:

 

AlfredoBIS_2-1657055978602.png

 

 

Transform date/time columns to date
Date must be related only to date

ı changed datakey format to date. 

But result didnt change . Year 2017i2018,2019 and grand total is not true

AlfredoBIS_0-1657056795051.png

 

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.