I want to remove weekends from a calculated column calculation. I am having a formula which calculate daily target:
Daily MAL Target = [MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date])))
In the marketing Targets table thers a seperate column to identify whether the date is working day or weekday as 1 and 0.
IsWorkDay = SWITCH(WEEKDAY([Date]),1,0,7,0,1)
I want to add "IsWorkingDate=1" to the above Daily Mal Target formula. It is a calculated column. I have tried so many ways but could not do it.
Can anyone help me on this?
You can use this DAX expression to check for weekdays:
= IF(OR(WEEKDAY([Date]) = 1, WEEKDAY([Date) = 7), "Calculation for Weekdays", "Calculation for Mo to Fr")
If it's a calculated column, you can use an if condition to make the value 0 or blank for weekends:
Daily MAL Target = IF(WEEKDAY(Marketing_targets_MALMEL[Date]) in {1,7},
BLANK(),
([MAL_Qtarget_A] /
(ENDOFQUARTER(Marketing_targets_MALMEL[Date]) -
ENDOFQUARTER(PREVIOUSQUARTER(Marketing_targets_MALMEL[Date]))))
Hope this helps.
Related
I am using power BI and I would like to create a line chart which contains values from two tables (sales history and sales prediction). So for the past 12 months, the line should reprensent the sales history and for the next 6 months, the line reprensents sales prediction. Here is what the data looks like, lets say we are in June 2021:
I know there is a way to do it in DAX but I don't know how to do it by myself. Thanks a lot in advance for your help !
You can achieve this by
Delete any relationship between Calendar and the other two tables if there is any, as we are going to use DATESBETWEEN function to calculate
Create two metric like below, you might need to adjust the column names as per your project
Sales History Amount = IF('CALENDAR'[Date] <= TODAY(), CALCULATE(SUM('Sales History'[Amount]), DATESBETWEEN('Sales History'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Sales Prediction Amount = IF('CALENDAR'[Date] >= TODAY(), CALCULATE(SUM('Sales Prediction'[Amount]), DATESBETWEEN('Sales Prediction'[Date], MIN('CALENDAR'[Date] ), MAX('CALENDAR'[Date]))), BLANK())
Add these two metrics in the table and use the Date from the Calendar table as X axis.
Format the first metric to solid line, and dash line for the second
Calendar should be linked to your tables.
Prediction Amount =
VAR lastSalesDate = MAX('Sales History'[Date])
VAR currentPredictionAmnt =
CALCULATE(
SUM('Sales Prediction'[Amount])
,KEEPFILTERS('CALENDAR'[Date]>lastSalesDate)
)
RETURN currentPredictionAmnt + SUM()
Sales Amount =
SUM('Sales History'[Amount])
[Please refer to the below image. I want to create a stacked column chart but I don't have a column that includes 0-30, 30-60, 60-90, etc. How did I put this range on X-axis?
And I didn't understand what kind of measure is used for "LAST 3 MONTH average" & "LAST 12 MONTH average ".
Can you please assist me with the same? ]
https://i.stack.imgur.com/AEnoa.png
Here is Microsoft documentation on using grouping and binning features in Power BI: https://learn.microsoft.com/en-us/power-bi/create-reports/desktop-grouping-and-binning
You can create a measure for last 3 month average like this:
3 Month Average = CALCULATE(
AVERAGE(Table[value]),
FILTER(Table,
Table[date] >= DATE(YEAR(TODAY()),MONTH(TODAY()-3),DAY(TODAY()))
)
)
I am getting the following error message when I write the below code:
Value for 'Total Sales'cannot is determined. Either 'Total Sales' does not exist or there is no current row for a column named 'Total Sales'
enter code here
LYSales = CALCULATE([Total Sales],SAMEPERIODLASTYEAR('Date'[Date]))
How do I fix this? I have the Total Sales column with data. It is set to general currency.
Written in this way your formula is not referencing a measure, not a column, also you will need an expression inside calculate.
-- This reference a Measure, which in your case is not defined
LYSales = CALCULATE([Total Sales],SAMEPERIODLASTYEAR('Date'[Date]))
-- you can create it with this formula
Total Sales = SUM('_TableName_'[Total Sales])
--The other way is to use only one formula
LYSales = CALCULATE(SUM('_TableName_'[Total Sales]),SAMEPERIODLASTYEAR('Date'[Date]))
As a note, to use time intelligence functions you need to mark the calendar table as "date table": right click on the table -> "Mark as Date Table"
The calculation looks at the table column as a whole. Your formula uses the value in the current row of the column. So, change it to
LYSales = CALCULATE('Your Table Name'[Total Sales],SAMEPERIODLASTYEAR('Date'[Date]))
I couldn't find an answer for my issue elsewhere, so trying my luck here.
I have sales table and my final result should determine if there were sales made for same person in specific period of time, for example within 7 business days. for example:
For ID 123 I have to flag it that sale for products A,B,C where within specified period.
For ID 1234 only sales of products A and B meet the criteria product C was sold in irrelevant time frame.
I've created a date table with indicators that determine for each date if the date is a working day, but i am struggling to calculate the relevant last working day
For example: I need that for 01/01/2019 i will get 10/01/2019 date, based on NUMOFDAYS and FinalWorkday = TRUE, which basically means that i have to count NUMOFDAYS times TRUE statement for each date and return corresponding date.
After that step done I think that it would be pretty easy for me to determine if the sale for a person was made in specific time frame.
If someone can give me direction for that much appreciated
Thank you in advance
You could use a DateTable like this one:
I used the following DAX-expressions for the calculated columns:
nrDays = 7
isWorkDay = WEEKDAY('DateTable'[Date],2) < 6
rankWorkingDays = RANKX ( FILTER ( DateTable, DateTable[isWorkDay] = TRUE () ),
DateTable[Date] , , ASC )
LastWorkDay = LOOKUPVALUE ( DateTable[Date],
DateTable[isWorkDay], TRUE (),
DateTable[rankWorkingDays], DateTable[rankWorkingDays] + DateTable[nrDays])
This issue can be solved by the following, since three are non-working days/holidays we can filter them out via POWERQUERY, than add an Index Column and Another column Which is basically Index column + Number of days wanted, then simply merge duplicate of dates query on Index+number of days wanted column on Index column. And we get the correct date
I am trying to calculate the number of working days between two dates in PowerBI excluding the weekends.
So, I have a table called as Calendar which has the date coming from 2000-2030 and another table which has the submitted date and today's date.
Where am I going wrong in this? My Calculated field Aging is showing wrong values and I cannot Identify why this is happening.
Tried with a measure and it says single value for Submitted_Date cannot be determined.
Aging2 = CALCULATE(SUM('Calendar'[IfWorkDay]),DATESBETWEEN('Calendar'[Date],(AgingReport[Submitted_Date]),(AgingReport[Today's Date])))
As a Column:
_dc_Vol_TTR_BDays = // BusinessDays
SUMX(
SELECTCOLUMNS(
CALENDAR([_scCreatedDateYMD], [_scLastActiveDateYMD]),
"Date", [_scCreatedDateYMD],
"BDay", IF(WEEKDAY([Date],3) < 5, 1, 0)
),
[BDay]
)
The Problem was with the data type. They both needs to be on the same date type.