cancel
Showing results for
Did you mean:

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

Helper I

## Separate DAX measures for time periods or can it be combined?

Hi

I've got multiple measures that are counting operations from the REST API based on dates.

- Operations total

- Operations in last 30 days

- Operations in last 90 days etc

Is there a more efficient way to do this without having 5 measures covering up to operations in the last 12 months?

2 ACCEPTED SOLUTIONS
Community Support

Hi @analyst85 ,

Based on my testing, please try the following methods:

1.Create the simple table.

2.Create the new table.

3.Create the new measure to calculate operations for time periods.

``````Operations Count =
SWITCH(
TRUE(),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 30 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -30, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 90 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -90, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 150 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -150, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 270 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -270, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 360 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -360, DAY))
)``````

4.Drag the measure into the column visual.

5.The result is shown below.

Best Regards,

Wisdom Wu

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

Resolver III

You could create this DAX table and link it your date.

``````Calendar Ageing =
VAR _today_date = TODAY()

VAR _result =
UNION (
ADDCOLUMNS (CALENDAR ( _today_date - 30, _today_date),    "Ageing Days", "Last 30 days",   "Ageing Days Order", 1)
, ADDCOLUMNS (CALENDAR ( _today_date - 90, _today_date),    "Ageing Days", "Last 90 days",   "Ageing Days Order", 2)
, ADDCOLUMNS (CALENDAR ( _today_date - 150, _today_date),   "Ageing Days", "Last 150 days",  "Ageing Days Order", 3)
, ADDCOLUMNS (CALENDAR ( _today_date - 270, _today_date),   "Ageing Days", "Last 270 days",  "Ageing Days Order", 4)
, ADDCOLUMNS (CALENDAR ( _today_date - 360, _today_date),   "Ageing Days", "Last 360 days",  "Ageing Days Order", 5)
)

RETURN
_result``````

2 REPLIES 2
Resolver III

You could create this DAX table and link it your date.

``````Calendar Ageing =
VAR _today_date = TODAY()

VAR _result =
UNION (
ADDCOLUMNS (CALENDAR ( _today_date - 30, _today_date),    "Ageing Days", "Last 30 days",   "Ageing Days Order", 1)
, ADDCOLUMNS (CALENDAR ( _today_date - 90, _today_date),    "Ageing Days", "Last 90 days",   "Ageing Days Order", 2)
, ADDCOLUMNS (CALENDAR ( _today_date - 150, _today_date),   "Ageing Days", "Last 150 days",  "Ageing Days Order", 3)
, ADDCOLUMNS (CALENDAR ( _today_date - 270, _today_date),   "Ageing Days", "Last 270 days",  "Ageing Days Order", 4)
, ADDCOLUMNS (CALENDAR ( _today_date - 360, _today_date),   "Ageing Days", "Last 360 days",  "Ageing Days Order", 5)
)

RETURN
_result``````

Community Support

Hi @analyst85 ,

Based on my testing, please try the following methods:

1.Create the simple table.

2.Create the new table.

3.Create the new measure to calculate operations for time periods.

``````Operations Count =
SWITCH(
TRUE(),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 30 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -30, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 90 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -90, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 150 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -150, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 270 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -270, DAY)),
SELECTEDVALUE('Table Period'[Date Period]) = "Last 360 days", CALCULATE(SUM('Table'[Operations]), DATESINPERIOD('Table'[Date], LASTDATE('Table'[Date]), -360, DAY))
)``````

4.Drag the measure into the column visual.

5.The result is shown below.

Best Regards,

Wisdom Wu

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

Announcements

#### New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

#### Power BI Monthly Update - May 2024

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

#### Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors
Top Kudoed Authors