Show only one day of the week in Date column - powerbi

I've created a Date column and used the calendar function to list a date range. Here's the DAX formula I used:
Data = Calendar( Date(2018, 4, 1), Date(2021,4,30))
However, what I'm trying to achieve now that I have the date range specified is I only want Tuesdays to be shown and no other day of the week. How do I achieve this exactly?
Apologies if this is a silly question, I'm completely new to this.
I tried using the Date filters option but that didn't help unfortunately. Thank you!

Simply use a FILTER function:
Data = FILTER(
Calendar( Date(2018, 4, 1), Date(2021,4,30)),
WEEKDAY([Date]) =3)
Bonus for confirmation:
If we want to confirm:

I hope you can accept this answer:
Data =
VAR tbl =
ADDCOLUMNS(
CALENDAR( DATE(2018, 4, 1), DATE(2021, 4, 30)),
"Weekday", WEEKDAY([Date], 2)
)
RETURN
SELECTCOLUMNS(
FILTER( tbl, [Weekday] = 2),
"Date", [Date]
)

Related

Summarize Daily working events without including time from the next dates activity in Power BI

I have a table with a log of daily events:
1
and a related date table
I would like to be able to sum up the total time of events that happen within each given date. The output would look like this:
2
Is there a simple way of doing this with dax? I have done it in the past with multiple calculated columns and I would like to avoid that.
Try this using calculated tables:
Split your overnight shifts into daily chunks
Aggregate the results
Split work per date =
VAR thisdate =
SELECTCOLUMNS(
'Work',
"Date", DATEVALUE('Work'[Start Datetime]),
"Minutes",
IF( DATEVALUE('Work'[Start Datetime]) <> DATEVALUE('Work'[End Datetime]),
ROUND((DATEVALUE('Work'[End Datetime]) - 'Work'[Start Datetime]) * 24 * 60, 0),
ROUND(('Work'[End Datetime] - 'Work'[Start Datetime]) * 24 * 60, 0) ) )
VAR nextdate =
SELECTCOLUMNS(
'Work',
"Date", DATEVALUE('Work'[Start Datetime]) + 1,
"Minutes",
IF( DATEVALUE('Work'[Start Datetime]) <> DATEVALUE('Work'[End Datetime]),
ROUND(('Work'[End Datetime] - DATEVALUE('Work'[End Datetime])) * 24 * 60, 0),
0 ) )
RETURN
UNION( thisdate, nextdate)
Power BI can already aggregate 'Split work per date'[Date] and 'Split work per date'[Minutes] in a table visual:
But you can also do this "manually" in another table:
Summarize work per date =
SUMMARIZE(
'Split work per date',
'Split work per date'[Date],
"Minutes", SUM('Split work per date'[Minutes])
)

Power BI how to add a new row based on condition after group

I have a table like this:
enter image description here
I want to create a default value for each group(each month should have a default amount 0), I know we should do group function first, but I do not know want to do next, very appreciate who give me help
I'm not sure exactly where you are going with your request. I understand it as: Adding a row for the first day of each month with a default value of zero.
This is not easy DAX. It's a bit complicated, so feel free to provide more info about your need, there may be another way more simple way.
The first step is to generate a table of the first day of each month. After a quick search, I've found a way in another answer and I was able to modify it a bit.
TABLE2 =
SELECTCOLUMNS(
FILTER(
ADDCOLUMNS(
CALENDAR(
DATE(2022, 01, 01),
DATE(2022, 12, 01)
),
"IsFDOM",
IF(
DAY([Date]) = 1,
TRUE(),
FALSE()
)
),
[IsFDOM] = TRUE()
),
"DATA",
[Date],
"AMOUNT",
0
)
What it does:
It generate a calendar between two dates I've arbitrary set : January 1st to Decembre 1st.
It adds a columns in this generated table IsFDOM (Is First Day Of Month) that return True is it is.
This table is then filtered to keep only the rows where IsFDOM is True.
It is wrapped in a SELECTCOLUMNS to keep and rename the columns you want and to match your existing table.
Next, you want to merge your existing table with this newly generated table. The DAX function to do it is UNION and requires both table to have the same format - i.e same number of columns.
TABLENEW =
UNION(
TABLE1,
FILTER(
TABLE2,
NOT TABLE2[DATA] IN VALUES(TABLE1[DATA])
)
)
I've named you existing table TABLE1 in this example.
The FILTER is used to not merge rows (dates) that already exist in TABLE1.
And, to make things even nicer. We can bypass the creation of TABLE2 by embedding it in the table expression of TABLENEW :
TABLENEW =
VAR MaxDate =
MAX(TABLE1[DATA])
VAR TMP_Calendar =
FILTER(
SELECTCOLUMNS(
SUMMARIZE(
FILTER(
ADDCOLUMNS(
CALENDAR(
DATE(2022, 01, 01),
DATE(2022, 12, 01)
),
"IsFDOM",
IF(
DAY([Date]) = 1,
TRUE(),
FALSE()
)
),
[IsFDOM] = TRUE()
),
[Date],
"default",
0
),
"DATA",
[Date],
"AMOUNT",
[default]
),
NOT [DATA] IN VALUES(TABLE1[DATA]) &&
[DATA] <= MaxDate
)
RETURN
UNION(
TABLE1,
TMP_Calendar
)
The calendar formerly known as TABLE2 is now created in a variable TMP_Calendar.
To make thing nicer, MaxDate calculate the max date of your existing table and only merge for existing date.

Power Bi Dax - Measure that calculates one measure for a period and another if not in that timeframe

I am essentially trying to say from 1/1/2022 through 3/31/2022 use a certain measure and if not in that timeframe then use another measure. The purpose is for these months a different calculation was used to determine the total and for the remainder of the time it was the unchanged, so I want to see the total trended out over time that will not be filtered and for those 3 months show the 'Diff_Total'. I've tried a few things other than this and in this particular attempt it won't let me select a column from the 'Date_Table'...
= CALCULATE(IF(Date_Table > DATE(2022, 01, 01) && Date_Table < DATE(2022, 03, 31), [Diff_Total], [Original_Total]))
I've got it working with
Measure =
VAR Dateinrange =
AND(
min(Date_Table[Date]) > DATE(2022, 01, 01),
min(Date_Table[Date]) < DATE(2022, 03, 01)
)
RETURN IF(Dateinrange=TRUE(),[Diff_Total], [Original_Total])
Let me know if that works for you!

Calculate Ratio of Current and Previous Week per Task Type

I am fairly new to PowerBI and coming form an R background, I have some difficulties understanding how PowerBI decides in which context a measure is evaluated.
I have the following measures, which calculates the ratio between the previous and the current week:
AHT = DIVIDE(SUM('Daily Tasks'[SHT]), SUM('Daily Tasks'[#Tasks]))
AHT Current Week = CALCULATE([AHT], 'Dates'[Date] >= TODAY() - 7)
AHT Previous Week = CALCULATE([AHT], 'Dates'[Date] < TODAY() - 7 && 'Dates'[Date] >= TODAY() - 14)
AHT Ratio Week = DIVIDE([AHT Current Week], [AHT Previous Week])
So far so good. Now I want to display the smallest ratio in a card visual (together with the task type which features this ratio) . Thus, I created the following 2 measures:
Top of the Week % =
MAXX(
TOPN(
1,
SUMMARIZECOLUMNS(
'Daily Tasks'[Task Type],
"Ratio", [AHT Ratio Week]
),
[Ratio], ASC
),
[Ratio] - 1
)
Top of the Week =
CONCATENATEX(
TOPN(
1,
SUMMARIZECOLUMNS(
'Daily Tasks'[Task Type],
"Ratio", [AHT Ratio Week]
),
[Ratio], ASC
),
[Task Type]," - "
)
The visual shows the correct values and all seems fine. However, if I either select a task type in any of the other visuals, or use a slicer to filter but a single task type, the card visual shows an error saying that
SummarizeColumns and AddMissingItems must not be used in this context
So apparently something is amiss. How can I fix that?
SUMMARIZECOLUMNS does not support evaluation within a context transition. This makes it almost impossible to use in a measure. You will want to use Summarize instead.
Thanks to the hint of #Randy Minder I was able to solve the issue:
SUMMARIZE instead of SUMMARIZECOLUMNS did the trick.
I just needed to filter out BLANK values and ended up with the following code:
Top of the Week % =
MAXX(
TOPN(
1,
FILTER(
SUMMARIZE(
ALL('Daily Tasks'[Task Type]),
'Daily Tasks'[Task Type],
"Ratio",
[AHT Ratio Week]
),
NOT(ISBLANK([Ratio]))
),
[Ratio],
ASC
),
[Ratio] - 1
)

Custom Date Table Drill-down Issue Power BI

Using the built-in Power BI date table, you are able to drill down from year -> Qtr -> month effortlessly, as shown below:
The date table used to generate the drill-down figure above:
DAX Formula: Cal = CALENDAR(MIN(Data[Date]),MAX(Data[Date]))
I would like to maintain this drill-down capability for the following custom date table:
Dates =
GENERATE (
CALENDAR ( DATE ( 2016, 10, 1 ), DATE ( 2025, 10, 1 ) ),
VAR currentDay = [Date]
VAR year =
IF ( MONTH ( currentDay ) >= 10, YEAR ( currentDay ) + 1, YEAR ( currentDay ) )
VAR quarter =
IF (
MONTH ( currentDay ) >= 10,
1,
IF ( MONTH ( currentDay ) <= 3, 2, IF ( MONTH ( currentDay ) <= 6, 3, 4 ) )
)
VAR month =
IF (
MONTH ( currentDay ) >= 10,
MONTH ( currentDay ) - 9,
MONTH ( currentDay ) + 3
)
RETURN
ROW ( "year", year, "quarter", quarter, "month", month )
)
It seems that the moment I mark "Dates" as the date table, I am unable to implement the built-in drill-down capability. I tried adding a date hierarchy, but cannot seem to control the order of the drill-down. For example, the visuals display month initially, and then "drill-down" to year, and finally to quarter. (this order doesn't make sense to me and I can't seem to change it). I need to be able to go from year -> quarter -> month, as before. I cannot use the default date table because I am using fiscal dates.
This is the result I am getting:
Please let me know if anything needs clarification, thank you!
I am able to sort in custom date table(with different fiscal year), Please find the snapshot attached for your reference.
I have used the power query to create a custom date table ( you can find the code here https://radacad.com/create-a-date-dimension-in-power-bi-in-4-steps-step-2-fiscal-columns)
we just need to change the startdate, enddate and StartOfFiscalYear(custom fiscal month).
Try and let me know
You have defined your date hierarchy as Date > year > month > quarter, per your screenshot. The order of the fields in the hierarchy defines your drill order. You do not need to define a hierarchy, you can simply drop fields ad-hoc into the field well for any visual. But if you're using a hierarchy, you must define it in the correct order:
year > quarter > month > Date
You can see the order in your hierarchy:
You can reorder these fields by clicking and dragging them within the hierarchy, or by right clicking and selecting "Move up" or "Move down":