getpivotdata to fill out table

Copper Contributor

I am trying to use the numbers on the right as a key to get the value from the matching "Dinstinct Count of Rma Number" in the pivot table. I am not sure about how to use this function and the videos I have watched have not helped. I also want it to output a zero, but I should be able to do that with an isna()

RaymondP2255_0-1720791148974.png

Here are the pivot table fields if that helps.

RaymondP2255_1-1720791316010.png

Any help would be appreciated.

9 Replies

@RaymondP2255 

For such setup

image.png

it could be

=IFERROR( GETPIVOTDATA("[Measures].[Distinct Count of RMA Number]",$G$3,"[Table1].[Day]","[Table1].[Day].&[" & [@Day] & "]"), 0 )

@SergeiBaklan 

I am trying to replicate what you did for your table and for some reason my pivot table is outputting the date like this

RaymondP2255_0-1720801075838.png

My data looks like this:

RaymondP2255_1-1720801100611.png

Also my table isn't pulling the numbers when using the code you gave.

 

=IFERROR( GETPIVOTDATA("[Measures].[Distinct Count of Rma Number]",$B$4,"[Table4].[Day]","[Table4].[Day].&[" & [@Day] & "]"), 0 )

 

Any ideas as to what I am doing wrong?

I also can't seem to attach my excel file.

 

@RaymondP2255 

Better to discuss this with the file. You may put it on OneDrive, Google Drive, whatever, share to everyone and post the link here.

Also on which Excel platform/version you are and add you data to data model creating PivotTable or not?

@RaymondP2255 

Oops, as you use Distinct Count you use data model, this question is closed.

@RaymondP2255 

Step by step

- we add PivotTable as

image.png

In Power Pivot add column with Days

image.png

Be sure this setting in Options is On

image.png

Create table with all possible days

image.png

Within table in any cell start from = and click on any cell in Distinct Count of PivotTable

image.png

Enter. Formula like

=GETPIVOTDATA("[Measures].[Distinct Count of Rma number]",$H$6,"[Table1].[Day]","[Table1].[Day].&[12]")

appears.

Now let modify this

image.png

part of it on

image.png

Wrap formula with IFERROR, finally

=IFERROR( GETPIVOTDATA("[Measures].[Distinct Count of Rma number]",$H$6,"[Table1].[Day]","[Table1].[Day].&[" & [@Day] & "]"), 0 )

In Power Pivot add Year and Month columns if they were not created initially

=YEAR(Table1[Date])
=FORMAT(Table1[Date], "mmm" )

Add slicers or filters to PivotTable

Here we are

image.png

 

@RaymondP2255 

Got your file, thank you. Will repeat on it.

@RaymondP2255 

We need to add DAY column to data model

image.png

and in formula it shall be not $B$4

image.png

but $B$2, i.e. reference on Row labels cell

image.png

Please check attached

@RaymondP2255 

More complex variant if to use other cube formulae in combination with dynamic arrays

=LET(
 daysSet,        CUBESET("ThisWorkbookDataModel","[Table4].[Day].children"),
 SelectedMonths, CUBESET("ThisWorkbookDataModel", Slicer_Date__Month1),
 SelectedYears,  CUBESET("ThisWorkbookDataModel", Slicer_Date__Year1),
 DistinctCount,  CUBEMEMBER("ThisWorkbookDataModel","[Measures].[Distinct Count of Rma Number]"),
 daysList,       CUBERANKEDMEMBER("ThisWorkbookDataModel", daysSet, SEQUENCE(31)),
 AllCounts,      MAP( daysList, LAMBDA(v,
                     CUBEVALUE("ThisWorkbookDataModel",
                               DistinctCount,SelectedMonths,
                               SelectedYears,
                               v)
                 ) ),
 VSTACK(
   {"Day","RMA Distinct Count"},
   FILTER( HSTACK( daysList, AllCounts), AllCounts<>"") )
)

That formula gives

image.png

see in Model sheet