cancel
Showing results for
Did you mean:
New Member

## Show previous 6 months, dynamic

Hello,

New to Power BI, so I wanted to know if there is a way to dynamically create a line chart showing the past 6 months of my data.

In my data I have a "month_year" column, and to retrieve the current month everytime, so that I don't have to filter into the new date, I created a measure

Max Month = CALCULATE(max(Table1[month_year]), all(Table1)) and then created a new column

Latest = if(Table1[month_year]=[Max Month],"Curent Month","")

Now I can show the last 6 months easily by creating a hierarchy with month_year and filtering in the 6 month dates, but is there a formula I can use to dynamically display the last 6 months

data is suppose to just show the revenue growth for 6 months

1 ACCEPTED SOLUTION
Microsoft

Hi @sfong002,

In your scenario, you can create a calculated column using the following formula, then use the column in slicer. For more details, you can check the screenshots below.

```Date Periods =
VAR Datediff =
1
* ( Table1[Date] - TODAY () )
RETURN
SWITCH (
TRUE,
AND ( Datediff <= 0,Datediff >= -180 ), "Last 6 Months",
Datediff < 180, "Older than 6 Months"
)```

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 REPLIES 2
Microsoft

Hi @sfong002,

In your scenario, you can create a calculated column using the following formula, then use the column in slicer. For more details, you can check the screenshots below.

```Date Periods =
VAR Datediff =
1
* ( Table1[Date] - TODAY () )
RETURN
SWITCH (
TRUE,
AND ( Datediff <= 0,Datediff >= -180 ), "Last 6 Months",
Datediff < 180, "Older than 6 Months"
)```

Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Solution Sage

If you only need the last 6 months' data anywhere in your report, you can filter the data when you get it, via

• Edit Query,
• Click the filter drop-down on your date column,
• Click Date Filters > In the Previous...

If you need that filter applied to just one visual in your report, you may need some more dynamic filtering such as that described by Chris Webb at Building Relative Date Reports in PowerPivot

Announcements