Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
ivandgreat
Helper II
Helper II

Check Date if Falls from previous and current month dates

Hello,

 

Im just having a hard time how to come up the results.

 

I have column date, i wanted to check if it falls from date range 26th from previous  month until 25th of the current month.

 

DateExpected Month Output
1/26/2022Jan
2/5/2022Jan
2/4/2022Jan
2/25/2022Jan
2/27/2022Feb
3/25/2022Feb

 

Thanks in advance.

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Use this formula in a custom column

= Date.ToText(Date.AddDays([Date],-25),"MMM")

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MtU3MjAyUorVAfPMEDwjfVNkjgkyxwhFClWXkTmCZ4yi0hihMhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Month", each Date.ToText(Date.AddDays([Date],-25),"MMM"), type text)
in
    #"Added Custom1"

 

View solution in original post

3 REPLIES 3
v-eqin-msft
Community Support
Community Support

Hi @ivandgreat ,

 

  • Method1: Add a column in Power Query:
[ 
d=Date.Day([Date]),
f=if d>=26 then [Date] else Date.AddMonths([Date],-1),
m=Text.Start(Date.MonthName(f),3)
][m]

Eyelyn9_0-1656386616228.png

 

  • Method2: Add a column using DAX:
Month = 
var _m=IF(DAY([Date])>=26, MONTH([Date]), MONTH([Date])-1)
return FORMAT( CONVERT(_m &"/1",DATETIME),"mmm")

Eyelyn9_1-1656387505334.png

 

 Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

KT_Bsmart2gethe
Impactful Individual
Impactful Individual

Hi @ivandgreat ,

 

I am unsure if you mean the current month is Jun (i.e. now?) or the range at each row.

 

Below solution applied the conditional formula to replicate the column "Expected Month Output"

if it is what you're looking for, please add a custom column and add formula below:

if ([Date]>Date.AddMonths(#date(Date.Year([Date]),Date.Month([Date]),25),-1)) and ([Date]<#date(Date.Year([Date]),Date.Month([Date]),26)) then Date.ToText(Date.AddMonths([Date],-1),"MMM") else Date.ToText([Date],"MMM")

KT_Bsmart2gethe_1-1655895808397.png

Let me know if this is what you're looking for.

 

Regards

KT

 

 

 

 

 

 

Vijay_A_Verma
Super User
Super User

Use this formula in a custom column

= Date.ToText(Date.AddDays([Date],-25),"MMM")

See the working here - Open a blank query - Home - Advanced Editor - Remove everything from there and paste the below code to test

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ3MtU3MjAyUorVAfPMEDwjfVNkjgkyxwhFClWXkTmCZ4yi0hihMhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    #"Added Custom1" = Table.AddColumn(#"Changed Type", "Month", each Date.ToText(Date.AddDays([Date],-25),"MMM"), type text)
in
    #"Added Custom1"

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Kudoed Authors