cancel
Showing results for
Did you mean:
Frequent Visitor

## how to use a last existing value, instead of lacking row

Hello! I’m trying to find a solution for several days already. Is it possible to create a measure with logic like: if there is no data on asked date, then show the last known value from the past.

Imagine a manufacturing site filled with machines like welding machines, calibrators etc.. Each product that is being produced there has its own route and cycle time per each machine it goes through. For example, the picture below showing that selected item 10PP11-01..81 starting from 1 of Jan 2018 has Cycle time 7 seconds with 1,2,3,4 "bubble" machines. On 1st of Jan, 2019 cycle time is going to be reduced from 7 to 5 seconds for first 2 machines.

Rows: Machines[machine_title]

Columns: Calendar[calendar]

Values: Assembly[cycletime]'

Slicer: Products[product_title]

I need to fill the empty cells with the last known value like this:

In the Calendar table I've got all dates starting from 2018 to 2022

In the Assembly table are stored only the starting dates and values like cycle time, cycles oee and parts per cycle.

How and what is the most efficient way of implementation?

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Microsoft

## Re: how to use a last existing value, instead of lacking row

Rather than directly placing Assembly[cycletime] into Matrix values, please add below measure:

```sum cycletime =
VAR mindate =
CALCULATE (
MAX ( Calendar[calendar] ),
FILTER (
ALLSELECTED ( Assembly ),
Machines[machine_title] = SELECTEDVALUE ( Machines[machine_title] )
&& Calendar[calendar] <= SELECTEDVALUE ( Calendar[calendar] )
&& Assembly[cycletime] <> BLANK ()
)
)
VAR maxdate =
SELECTEDVALUE ( Calendar[calendar] )
RETURN
CALCULATE (
SUM ( Assembly[cycletime] ),
FILTER (
ALLSELECTED ( Assembly ),
Machines[machine_title] = SELECTEDVALUE ( Machines[machine_title] )
&& Calendar[calendar] >= mindate
&& Calendar[calendar] <= maxdate
)
)```

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
3 REPLIES 3
Frequent Visitor

## If there is no data on asked date, show the last known value from the past

Hello! I’m trying to find a solution for several days already. Is it possible to create a measure with logic like: if there is no data on asked date, then show the last known value from the past.

Imagine a manufacturing site filled with machines like welding machines, calibrators etc.. Each product that is being produced there has its own route and cycle time per each machine it goes through. For example, the picture below showing that selected item 10PP11-01..81 starting from 1 of Jan 2018 has Cycle time 7 seconds with 1,2,3,4 "bubble" machines. On 1st of Jan, 2019 cycle time is going to be reduced from 7 to 5 seconds for first 2 machines.

Rows: Machines[machine_title]

Columns: Calendar[calendar]

Values: Assembly[cycletime]'

Slicer: Products[product_title]

I need to fill the empty cells with the last known value like this:

In the Calendar table I've got all dates starting from 2018 to 2022

In the Assembly table are stored only the starting dates and values like cycle time, cycles oee and parts per cycle.

How and what is the most efficient way of implementation?

Thank you

Microsoft

## Re: how to use a last existing value, instead of lacking row

Rather than directly placing Assembly[cycletime] into Matrix values, please add below measure:

```sum cycletime =
VAR mindate =
CALCULATE (
MAX ( Calendar[calendar] ),
FILTER (
ALLSELECTED ( Assembly ),
Machines[machine_title] = SELECTEDVALUE ( Machines[machine_title] )
&& Calendar[calendar] <= SELECTEDVALUE ( Calendar[calendar] )
&& Assembly[cycletime] <> BLANK ()
)
)
VAR maxdate =
SELECTEDVALUE ( Calendar[calendar] )
RETURN
CALCULATE (
SUM ( Assembly[cycletime] ),
FILTER (
ALLSELECTED ( Assembly ),
Machines[machine_title] = SELECTEDVALUE ( Machines[machine_title] )
&& Calendar[calendar] >= mindate
&& Calendar[calendar] <= maxdate
)
)```

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Frequent Visitor

## Re: how to use a last existing value, instead of lacking row

Yuliana, thank you very much!

To make it work I only had to make a separate variable 'selectedMachine' to avoid some errors.

This is the working code:

```sum cycletime =
VAR selectedMachine = SELECTEDVALUE(machines[m.machine_id])
VAR mindate =
CALCULATE (
MAX ( calendar[calendar] ),
FILTER (
ALLSELECTED ( assembly ),
assembly[machine_id] = selectedMachine
&& assembly[date] <= SELECTEDVALUE ( calendar[calendar] )
&& assembly[ctime] <> BLANK ()
)
)
VAR maxdate =
SELECTEDVALUE ( calendar[calendar] )
RETURN
CALCULATE (
AVERAGE( assembly[ctime] ),
FILTER (
ALLSELECTED ( Assembly ),
assembly[machine_id] = selectedMachine
&& assembly[date]>= mindate
&& assembly[date] <= maxdate
)
)```

Announcements

#### Announcing the New Spanish Forum

Do you need help in Spanish? Check out our new Spanish community section.

#### April 2020 Community Highlights

Info on our Super Users, MBAS content and badges, and updates to our support articles. - Read the full Community Highlights.

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

Top Solution Authors
Top Kudoed Authors