Calculated column to count number of weeks from a previous response in data

adamzee

New Member
Joined
Apr 12, 2015
Messages
9
So I have a list of stores that are called upon sales reps. The sales reps do a check of a demonstration unit each time they visit. Is there a way in PowerPivot if the demonstration unit is not operational to count the number of weeks it has not been operational? Example is below.
Any help would be appreciated.


Store NameDemonstration Unit Operational?Week Number of weeks non operational *Calculated Column*
Store 1Yes1
Store 2Yes1
Store 3Yes1
Store 4No1
Store 1Yes2
Store 2Yes2
Store 3Yes2
Store 4No21
Store 1Yes3
Store 2Yes3
Store 3Yes3
Store 4No32

<colgroup><col><col><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,
try this: =if([Demonstration Unit Operational?]="No", CALCULATE(DistinctCOUNT([Week]), Filter(Table;[Demonstration Unit Operational?]="No" &&[Store Name]=[Store Name] && [Week] "is less than" EARLIER([Week]))),blank())

"is less than" should be the symbol on your keybord
 
Upvote 0
Hi,
this editor strikes, will try next post:

Thanks heaps ImkeF, I am using the below dax formula for the spreadsheet. However am getting an error. I am fairly new to dax so any help would be appreciated.


=if([Demonstration Unit Operational?]="No", CALCULATE(DistinctCOUNT([Week])-1, Filter(Table1[Demonstration Unit Operational?]="No" &&[Store Name]=[Store Name] && [Week]<=EARLIER([Week]) )),blank())
 
Upvote 0
What does the error message say?

The Expression around the Filter-Statement doesn't look OK: Filter(Table, condition) - you need to place a comma after the table name and then continue with the conditions:

=if([Demonstration Unit Operational?]="No", CALCULATE(DistinctCOUNT([Week])-1, Filter(Table1, [Demonstration Unit Operational?]="...
 
Upvote 0
What does the error message say?

The Expression around the Filter-Statement doesn't look OK: Filter(Table, condition) - you need to place a comma after the table name and then continue with the conditions:

=if([Demonstration Unit Operational?]="No", CALCULATE(DistinctCOUNT([Week])-1, Filter(Table1, [Demonstration Unit Operational?]="...

Thanks heaps ImkeF, that worked perfectly.
 
Upvote 0
Hi adamzee :)
You can also use PQ to do this and then add the result to your data model.
Code for PQ:
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Tabela1"]}[Content],
    AddIndex = Table.AddIndexColumn(Source, "Indeks", 0, 1),
    FilterRows = Table.SelectRows(AddIndex, each ([Demonstration Unit] = "No")),
    GroupedRows = Table.Group(FilterRows, {"Store Name", "Demonstration Unit"}, {{"Group", each _, type table}}),
    AddIndexToTable = Table.AddColumn(GroupedRows, "Custom", each Table.AddIndexColumn([Group], "NonOperWeeks", 0, 1)),
    RemOtherCol = Table.SelectColumns(AddIndexToTable,{"Custom"}),
    ExpCustom = Table.ExpandTableColumn(RemOtherCol, "Custom", {"Indeks", "NonOperWeeks"}, {"Indeks1", "NonOperWeeks"}),
    LeftOuter = Table.Join(AddIndex,{"Indeks"},ExpCustom,{"Indeks1"},JoinKind.LeftOuter),
    RemoveColumns = Table.RemoveColumns(LeftOuter,{"Indeks", "Indeks1"})
in
    RemoveColumns

You have to change "source" to your data source, of course.

Regards
 
Upvote 0

Forum statistics

Threads
1,215,634
Messages
6,125,938
Members
449,275
Latest member
jacob_mcbride

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top