I currently have a date field with the format 01 January 2022, 04 February 2022 Etc
I am trying to create a column that pulls out the month in MMM format (JAN, FEB)
Using Month = Month('Current Week'[Created On])
This pulls the numbered date of the month (1,2)
I tried to add in format but this does not work as Month only allows 1 argument.
What else can I do to pull out the month format that I am looking for?
Try this one:
Month String =
UPPER(
FORMAT(
DATEVALUE('Current Week'[Created On]),
"mmm"
)
)
Related
How do I get the week ending date from week no. in GCP ?
SELECT
Session,
Store_Num,
Store_Name,
EXTRACT (WEEK(Monday) from Route_Date) as Weekno,
AVG(Planned_DPH) as Avg
FROM `TABLE`
WHERE Route_Date between current_date() - 60 and current_date()
and Store_Num = 8881
GROUP BY 1,2,3,4
ORDER BY Weekno
You can get the first day of weekno with PARSE_DATE function and %W format string.
%W - The week number of the year (Monday as the first day of the week) as a decimal number (00-53).
And by adding 6 more days to the first day of the week, you will get the week ending date.
Consider below sample query.
WITH sample_data AS (
SELECT DATE '2022-11-10' AS Route_Date
)
SELECT *,
PARSE_DATE('%Y%W', Year || Weekno) AS startday_of_weekno,
PARSE_DATE('%Y%W', Year || Weekno) + 6 AS lastday_of_weekno
FROM (
SELECT EXTRACT(WEEK(Monday) from Route_Date) as Weekno, -- 45
EXTRACT(YEAR FROM Route_Date) AS Year,
FROM sample_data
);
Query results
I need to generate the dates from start date and end date. For example, Start date is 11th March 2022 and the end date is 11th March 2023.
I have been able to generate the dates from 11th March 2022 to 1st March 2023 using the below formula in power query
let
StDt = [#"Grant date #(lf)(dd/mm/yyyy)"],
AllDates = {Number.From([#"Grant date #(lf)(dd/mm/yyyy)"])..Number.From([#"Vesting end date (each period)"])},
StofMonthDates =
List.Distinct(List.Select(List.InsertRange(List.Transform(AllDates, each Date.StartOfMonth(Date.From(_))),0,{[#"Grant date #(lf)(dd/mm/yyyy)"]}),each Number.From (_) >= Number.From(StDt)))
in
StofMonthDates
In the above query, Grant date means start date and Vesting end date means end date. I need to get the date as on the end date i.e., 11th March 2023 and not only the start of the month i.e., 1st March 2023
In Add Column section ,choose Custom Column and use following formula where Number.From transform your date column to its Corresponding number
={ Number.From([Start_Date])..Number.From([End_Date]) }
it generate numbers, then you should your numbers to date.
I have a table containing a date field (from 1 March 2020 to now) that I need to filter to a specific date and the previous 6 days to give complete week's data. So if I chose 30 March I'd get a table of 24 March to 30 March. If I then chose 31 March the table would show 25 March to 31 March.
I can use a date slicer to choose a range of dates but I want to be able to pick a single date, with Power BI automatically selecting the earlier date.
Any pointers much appreciated.
Mark.
You can create two measure - one for Slicer selected date and Another one with 7 day minus from the selected date as below-
Considering your date table name is- Dates
selected_date = SELECTEDVALUE(Dates[Date])
seven_day_starts_from = DATEADD(Dates[Date],-7,DAY)
Now create your calculated measure first like-
total_sales = SUM(Sales[sale])
Here comes how you will always calculate last 7 days sales considering the selected date in the slicer-
7_day_sales =
(
CALCULATE(
[total_sales],
DATESBETWEEN(
'Dates'[Date],
[seven_day_starts_from],
[selected_date]
)
) + 0
)
Remember, this is just a sample flow showing how it should work. You should try to follow the steps with your data and table structure. Dates table is a calendar table and Sales table is connected to the Dates table using the Date column.
I have a column (monthyear) in the image below. I want to extract the Month and year from the column to put it in the new column. Note: In my dataset this information goes for every day of the year
So the new column would look like:
01/2020
01/2020
01/2020
etc.
In Power Query, use some of the date functions.
To get the year it will be
Date.Year([monthyear])
For the month, it will depend on how you want to format it. Using the month of June as an example:
To get 'Jun'
Date.ToText([monthyear],"MMM")
To get the month number in the format 06
Number.ToText(Date.Month([monthyear]), "00")
Just to get the number 6 it will be:
Date.Month([monthyear])
In DAX use the date functions
For year the calculated column will be:
YEAR([monthyear])
For the month:
MONTH([monthyear])
I would always do a much data transformation in Power Query when you can before it gets to the data model.
I'm currently struggling with following request in PowerBI:
I have two CSV files as PowerBI queries, one which defines fiscal months, and another one which lists all subscriptions including start and end date:
Fiscal month CSV:
Month Fiscal Start Fiscal End
January 03.01.2016 04.02.2016
February 05.02.2016 03.03.2016
March 04.03.2016 06.04.2016
April 07.04.2016 02.05.2016
May 03.05.2016 06.06.2016
June 07.06.2016 03.07.2016
July 04.07.2016 05.08.2016
August 06.08.2016 02.09.2016
Subscription CSV:
Account-ID Subscription-Start Subscription-End Item Count
101 08.01.2016 07.02.2016 5
102 15.01.2016 14.03.2016 3
103 05.01.2016 04.06.2016 10
101 08.02.2016 07.03.2016 3
104 10.04.2016 09.05.2016 5
105 16.04.2016 15.07.2016 2
My challenge now is to drill down all subscription item counts per fiscal month as a powerBI table.
Note: an Item Count is valid for a fiscal month if its Subscription-Start < Fiscal End and its Subscription-End > Fiscal End. (Example: A subscription from 15.01.2016 - 14.02.2016 should be counted in january, but not in february)
PowerBI table (schematical example):
Month Item Count
January 18
February 16
March 10
April 17
May 12
June 2
July 0
August 0
How can I implement this report in PowerBI?
THX in advance for your help and BR
bdriven
I've found following solution for my problem:
First I've created a new Table and made a crossjoin of the two queries. Then I've filtered for the lines, where my Subscription Start was before the Fiscal Month End and Subscription End was after the Fiscal Month End.
Based on this new table I can create all respective reports.
Example Code see below:
Fiscal Month Report =
FILTER(
CROSSJOIN(
ALL('Fiscal_month');
ALL('Subscription')
);
('Subscription'[Subscription-Start] < 'Fiscal_month'[Fiscal End] && 'Subscription'[Subscription-End] > 'Fiscal_month'[Fiscal End])
)