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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AnaIsa
Frequent Visitor

calculate date before

Hi, 

How I can calculate a previous date  since a column with a data time received. Example: I have a column with this date:

AnaIsa_0-1714433092187.png

 

I want to calculate a previous date, it would be 31/03/24

 

thank you

 

 

1 ACCEPTED SOLUTION
v-yaningy-msft
Community Support
Community Support

Hi, @AnaIsa 

Thanks for @lbendlin reply. This is an additional step to his response, if you are confused how to proceed, you can refer to the following methods.

1. Power Query

vyaningymsft_0-1714444806409.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRNzDUNzIwMlGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"ChangedType" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    AddedCustom = Table.AddColumn(ChangedType, "Previous Day", each Date.AddDays([Date], -1), type date)
in
    AddedCustom


2. Power BI Desktop

vyaningymsft_1-1714445953019.png

 

Previous Day 2 = 
VAR _previousDate = CALCULATE(SELECTEDVALUE('Table'[Date]) - 1)
RETURN
_previousDate

Or use Dateadd function directly.
DATEADD - DAX Guide

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

3 REPLIES 3
v-yaningy-msft
Community Support
Community Support

Hi, @AnaIsa 

Thanks for @lbendlin reply. This is an additional step to his response, if you are confused how to proceed, you can refer to the following methods.

1. Power Query

vyaningymsft_0-1714444806409.png

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjDRNzDUNzIwMlGKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date = _t]),
    #"ChangedType" = Table.TransformColumnTypes(Source,{{"Date", type date}}),
    AddedCustom = Table.AddColumn(ChangedType, "Previous Day", each Date.AddDays([Date], -1), type date)
in
    AddedCustom


2. Power BI Desktop

vyaningymsft_1-1714445953019.png

 

Previous Day 2 = 
VAR _previousDate = CALCULATE(SELECTEDVALUE('Table'[Date]) - 1)
RETURN
_previousDate

Or use Dateadd function directly.
DATEADD - DAX Guide

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

I would like to see the sales value for previous month at product detail, I only see it in a general table like this:

AnaIsa_0-1715207640344.png

but if I want to see by detail, If I select a month I see the same amount for AC and AC-1, the formula used for AC-1 is: 

Transit AC-1 = CALCULATE([Total Transit],(DATEADD('Date'[Date],-1,MONTH)))

AnaIsa_2-1715207911669.png

 

could you help me please ?

lbendlin
Super User
Super User

In Power Query you subtract #duration(1,0,0,0) . In DAX you subtract 1.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.