I'm looking for a DAX way to have a column in my table which corresponds to the DAY() function without weekend days. In France weekend days are Saturday and Sunday.
Like this:
Date|Month|Year|Rank of the day with weekend days|Rank of the day without weekend days
01/10/20201|10|2021|1|1
02/10/20201|10|2021|2|1
03/10/20201|10|2021|3|1
04/10/20201|10|2021|4|2
05/10/20201|10|2021|5|3
With DAX Calculated column
You need to have following two columns in the dataset itself
| Date | Day# | Week# | Ranking |
|---------------------------- |------ |------- |--------- |
| Friday, October 1, 2021 | 6 | 40 | 1 |
| Saturday, October 2, 2021 | 7 | 40 | 1 |
| Sunday, October 3, 2021 | 1 | 41 | 1 |
| Monday, October 4, 2021 | 2 | 41 | 2 |
| Tuesday, October 5, 2021 | 3 | 41 | 3 |
| Wednesday, October 6, 2021 | 4 | 41 | 4 |
| Thursday, October 7, 2021 | 5 | 41 | 5 |
| Friday, October 8, 2021 | 6 | 41 | 1 |
| Saturday, October 9, 2021 | 7 | 41 | 1 |
| Sunday, October 10, 2021 | 1 | 42 | 1 |
| Monday, October 11, 2021 | 2 | 42 | 2 |
| Tuesday, October 12, 2021 | 3 | 42 | 3 |
such as
Day# =
WEEKDAY ( 'Table'[Date], 1 )
Week# =
WEEKNUM ( 'Table'[Date] )
Ranking =
VAR _week =
CALCULATE ( MAX ( 'Table'[Week#] ) )
VAR _rank =
RANKX (
FILTER (
ALL ( 'Table' ),
'Table'[Week#] = _week
&& EARLIER ( 'Table'[Day#] ) <> 6
&& EARLIER ( 'Table'[Day#] ) <> 7
),
'Table'[Date],
,
ASC
)
RETURN
_rank
Related
Sample data:
+----------+------------+----------+-----------+
| PersonID | Date | Booked | Picked |
+----------+------------+----------+-----------+
| 1 | 1 Jan 2023 | 100 | 100 |
| 2 | 1 Jan 2023 | 40 | 30 |
| 3 | 1 Jan 2023 | 20 | 40 |
| 1 | 2 Jan 2023 | 50 | 80 |
| 2 | 2 Jan 2023 | 70 | 70 |
| 3 | 2 Jan 2023 | 60 | 40 |
+----------+------------+----------+-----------+
I have a measure as follows:
Performance % = DIVIDE(IF(Calls[Picked]>Calls[Booked],Calls[Booked],Called[Picked]),Calls[Booked])
I have formatted this as %
When I place this in a table visual then I get a % value.
But when I place it into a card visual then it forces me to choose sum/min/max/...
What is the way to display the value of a measure in a card visual?
How to iterate over each row to calculate the percentage value - for example - there is no DIVIDEX in dax.
Can you please try with a Measure as below-
Performance % =
DIVIDE(
IF(
SUM(Calls[Picked])>SUM(Calls[Booked]),
SUM(Calls[Booked]),
SUM(Calls[Picked])
),
SUM(Calls[Booked])
)
Could you please help me on below Dax logic
I am expecting my First_Valuecolumn needs to populate based on Date,datetime and subject column.
I have tried summarize and firstnoblank dax functions but doesn't useful for my requirement.
Thanks in advance,
PS
Assuming your data looks like this
Table
+-------------+---------------------+---------+-------+
| Date | DateTime | Subject | Value |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 01:00:00 | b | 2500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 01:00:00 | A | 6000 |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 01:00:00 | A | 4500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 01:00:00 | b | 1500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 02:00:00 | A | 4100 |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 02:00:00 | A | 4100 |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 02:00:00 | b | 3500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 02:00:00 | b | 3500 |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 03:00:00 | A | 5500 |
+-------------+---------------------+---------+-------+
| 05 May 2021 | 05/05/2021 03:00:00 | b | 7500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 03:00:00 | A | 5500 |
+-------------+---------------------+---------+-------+
| 06 May 2021 | 05/05/2021 03:00:00 | b | 7500 |
+-------------+---------------------+---------+-------+
You can create a calculated column as the following. The idea behind this is to create variables that can capture the values of the table and use them in filter contexts.
First_Value =
VAR SubjectValue = [Subject]
VAR DateVal = [Date]
VAR MinDateTime =
CALCULATE (
MIN ( [DateTime] ),
FILTER ( 'Table', [Subject] = SubjectValue && [Date] = DateVal )
)
RETURN
SUMMARIZE (
FILTER (
'Table',
[Subject] = SubjectValue
&& [Date] = DateVal
&& [DateTime] = MinDateTime
),
[Value]
)
I have a table resuming the list of apps by month and year like this:
Table 1
App | Month | Year
A | 1 | 2019
B | 1 | 2019
C | 1 | 2019
D | 1 | 2019
E | 1 | 2019
...
etc
And I have a table that contains the info of all the tickets of the company, including the App and the Month and Year, like this:
Table 2
IDTicket | App | Month | Year
44424 | B | 1 | 2019
44425 | D | 1 | 2019
44426 | B | 1 | 2019
44427 | A | 1 | 2019
44428 | E | 1 | 2019
...
etc
I need to add to the Table 1, a column that count the amount of tickets of Table 2 according to each app, month and year, like this:
Table1
App | Month | Year | CountOfTickets
A | 1 | 2019 | 1
B | 1 | 2019 | 2
C | 1 | 2019 | 0
D | 1 | 2019 | 1
E | 1 | 2019 | 1
Try something like this:
CountOfTickets =
CALCULATE (
COUNT ( Table2[IDTicket] ),
Table2[App] = EARLIER ( Table1[App] ),
Table2[Month] = EARLIER ( Table1[Month] ),
Table2[Year] = EARLIER ( Table1[Year] )
)
I have the following tables:
FactAssign { FactKey, BranchID, ClientID, CustomerName, StartDate, CalendarWeekKey, EmployeeguId }
DimBranch { BranchID, BranchName, Region}
DimClient { clientID, ClientName }
DimCalendar { CalendarWeekKey, WeekEndingDate, CalendarYear, CalendarWeek }
Data from FactAssign table here
Sample rows:
| BranchID | ClientID | StartDate | CalendarWeekKey | EmployeeGUID | DayofWeek |
|----------|----------|-----------|-----------------|--------------|-----------|
| 4 | 591 | 3/1/2019 | 20190303 | 783357 | Friday |
| 4 | 591 | 3/1/2019 | 20190303 | 3744071 | Friday |
| 4 | 591 | 3/1/2019 | 20190303 | 710020 | Friday |
| 4 | 591 | 3/1/2019 | 20190303 | 754929 | Friday |
| 4 | 3032 | 3/1/2019 | 20190303 | 4036981 | Friday |
| 4 | 5192 | 3/1/2019 | 20190303 | 731638 | Friday |
| 4 | 5192 | 3/1/2019 | 20190303 | 784118 | Friday |
| 4 | 5790 | 3/1/2019 | 20190303 | 756802 | Friday |
| 4 | 5790 | 3/1/2019 | 20190303 | 3748444 | Friday |
....
Result I need
Here CurrentWeek 50 is the Average of the distinct count of Employees per day for branchID 4 for this week. Distinct Counts of Employees this week are 56,53,48,47,46 respectively from Monday thru Friday.
How can I get the AVERAGE of the DISTINCTCOUNT of Employees per branch per Week?
Dax I used :
Averagex =
CALCULATE (
AVERAGEX (
VALUES ( TestingAverageX[CalendarWeekKey] ),
DISTINCTCOUNT ( TestingAverageX[EmployeeGUID] )
),
FILTER ( TestingAverageX, TestingAverageX[CalendarWeekKey] = 20190303 )
)
Regards,
Success
Solution to my question here:
AverageX = CALCULATE (
AVERAGEX (
VALUES ( TestingAverageX[StartDate] ),
CALCULATE ( DISTINCTCOUNT ( TestingAverageX[EmployeeGUID] ) )
)
I'm not sure exactly what filter context you want the measure to be evaluated in, but try something along these lines:
AVERAGEX(
VALUES( Table1[BranchName] ),
DISTINCTCOUNT( Table1[EmployeeID] )
)
I would like to compare the same period of sessions per day. If i'm looking at Oct 10th 2018 to Oct. 16th 2018 (Wednesday to Tuesday), I would like to compare it to the same day range of last week:
+------+-------+-----+----------+-------------+--+
| year | month | day | sessions | last_period | |
+------+-------+-----+----------+-------------+--+
| 2018 | oct | 10 | 2000 | 2500 | |
| 2018 | oct | 11 | 2500 | 2400 | |
| 2018 | oct | 12 | 2600 | 2300 | |
| 2018 | oct | 13 | 2700 | 2450 | |
| 2018 | oct | 14 | 2400 | 2500 | |
| 2018 | oct | 15 | 2300 | 2200 | |
| 2018 | oct | 16 | 2000 | 1150 | |
+------+-------+-----+----------+-------------+--+
A simple formula can make it work based on the 7-day interval:
same_last_period = CALCULATE(SUM(table[Sessions]),DATEADD(table[Date],-7,DAY))
but I would like the formula to depend on a date slicer. Say if i wanted to look at the Oct 1-Oct 20. I would like my formula to change and look at the same period right before with the same amount of day intervals. Ultimately this would be graphed as well.
Try this:
same_last_period =
VAR DayCount = CALCULATE(DISTINCTCOUNT(table[Date]), ALLSELECTED(table[Date]))
RETURN CALCULATE(SUM(table[Sessions]), DATEADD(table[Date], -DayCount, DAY))
Edit:
This above doesn't work how I intended since you still have the year, month, and day in your filter context. That needs to be removed.
same_last_period =
VAR DayCount =
CALCULATE (
DISTINCTCOUNT ( 'table'[Date] ),
ALLSELECTED ( 'table'[Date] ),
ALLEXCEPT ( 'table', 'table'[Date] )
)
RETURN
CALCULATE (
SUM ( 'table'[Sessions] ),
DATEADD ( 'table'[Date], -DayCount, DAY ),
ALLEXCEPT ( 'table', 'table'[Date] )
)
The ALLEXCEPT removes any extra filter context except for Date.