Apply different date filters to specific column values in a pivot table

%3CLINGO-SUB%20id%3D%22lingo-sub-3106994%22%20slang%3D%22en-US%22%3EApply%20different%20date%20filters%20to%20specific%20column%20values%20in%20a%20pivot%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3106994%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3ESuppose%20I%20have%20the%20following%20pivot%20table%20from%20one%20data%20source%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22edb9afcecb8ba2370bef7b2e1146b13d.png%22%20style%3D%22width%3A%20744px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F344744iD26ED55F964C970D%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22edb9afcecb8ba2370bef7b2e1146b13d.png%22%20alt%3D%22edb9afcecb8ba2370bef7b2e1146b13d.png%22%20%2F%3E%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThe%20source%20data%20is%20essentially%20a%20spreadsheet%20of%20accounts%20which%20indicates%203%20items%20(3%20columns)-%20date%20account%20was%20created%2C%20date%20account%20was%20successful%2C%20date%20account%20was%20bought.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThere%20are%203%20stages%20an%20account%20goes%20through%3A%20step%201%20it%20gets%20created.%20Step%202%2C%20if%20the%20employee%20deems%20the%20account%20to%20be%20successful%2C%20they%20mark%20it%20as%20successful%20and%20mark%20the%20date%20it%20became%20successful.%20If%20there%20is%20more%20interest%20in%20the%20account%2C%20the%20account%20is%20bought%20and%20the%20company%20receives%20money%20for%20it%20-%20they%20mark%20the%20date%20it%20was%20bought.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EIf%20you%20look%20at%20the%20data%2C%20the%20%23%20of%20created%20accounts%20%26gt%3B%20%23%20of%20successful%20accounts%20%26gt%3B%20%23%20of%20bought%20accounts.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EHowever%2C%20a%20created%20account%20can%20be%20made%20in%20Jan%202021%20for%20example%2C%20but%20can%20be%20successful%20in%20Feb%202021%20and%20then%20bought%20in%20June%202021.%20An%20account%20cannot%20necessarily%20be%20created%2C%20be%20successful%2C%20and%20be%20bought%20all%20in%20the%20same%20month%2Fyear.%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3EThat's%20the%20problem%20I%20have%20with%20this%20pivot%20table%20-%20the%20values%20field%20I%20have%20is%20using%20the%20count%20of%20date%20created%2C%20count%20of%20date%20successful%20and%20the%20columns%20on%20my%20pivot%20table%20is%20grouped%20by%20quarters%20of%20Y2021.%20The%20rows%20of%20the%20pivot%20table%20are%20the%20different%20regions%20the%20account%20belongs%20to.%20The%20problem%20I%20have%20is%20I%20am%20grouping%20the%20dates%20based%20on%20the%20date%20created%20and%20data%20is%20being%20filtered%20strictly%20from%20that%20date%20created%20filter%3B%20I%20don't%20know%20how%20to%20create%20a%20%22global%22%20date%20filter%20that%20is%20not%20strictly%20based%20on%20the%20date%20created%20filter%3C%2FSPAN%3E%3CBR%20%2F%3E%3CBR%20%2F%3E%3CSPAN%3ESo%2C%20in%20the%20February%202021%20column%20for%20example%2C%20it%20is%20telling%20me%20I%20have%208%20created%20accounts%20and%206%20successful%20accounts%2C%20when%20there%20really%20should%20be%205%20successful%20accounts.%20If%20you%20double%20click%20that%20cell%20which%20launches%20a%20table%20of%20that%20data%2C%20you'll%20see%20an%20account%20that%20was%20successful%20in%20August%202021%2C%20however%2C%20it%20was%20created%20in%20February%202021%2C%20so%20that%20is%20why%20it%20will%20say%206%20successful%20accounts%20.%20That%20is%20an%20example%20of%20a%20discrepancy%20in%20my%20pivot%20table.%20If%20region3%20has%2010%20created%20accounts%20in%20January%202021%20for%20example%2C%20and%20in%20the%20same%20month%2Fyear%2C%20has%205%20successful%20accounts%20(by%20looking%20at%20the%20source%20data)%20and%20one%20account%20becomes%20successful%20in%20July%202021%2C%20the%20pivot%20table%20should%20indicate%20that%20correctly%20as%2010%20created%20accounts%20in%20Jan%202021%20and%205%20successful%20accounts%20in%20January%202021.%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-3106994%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3107507%22%20slang%3D%22en-US%22%3ERe%3A%20Apply%20different%20date%20filters%20to%20specific%20column%20values%20in%20a%20pivot%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3107507%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F1295191%22%20target%3D%22_blank%22%3E%40tytds%3C%2FA%3E%26nbsp%3B%3CBR%20%2F%3Enot%20sure%20I%20understood%20entire%20logic.%20For%20such%20sample%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22image.png%22%20style%3D%22width%3A%20726px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F344803iAF341A5835BFB8E2%2Fimage-size%2Flarge%3Fv%3Dv2%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22image.png%22%20alt%3D%22image.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E-%20creating%20PivotTable%20add%20data%20to%20data%20model%3C%2FP%3E%0A%3CP%3E-%20add%20Date%20(Calendar)%20table%20with%20PowerPivot%20or%20Power%20Query%3C%2FP%3E%0A%3CP%3E-%20make%20relationship%20between%20it%20and%20main%20table%20on%20Date%20%26lt%3B%3D%26gt%3B%20Made%3C%2FP%3E%0A%3CP%3E-%20add%20measures%20as%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3Eaccounts%20made%3A%3DCOUNTROWS%20(%20Table1%20)%0A%0Aaccounts%20success%3A%3DVAR%20mindate%20%3D%0A%20%20%20%20MIN%20(%20'Calendar'%5BDate%5D%20)%0AVAR%20maxDate%20%3D%0A%20%20%20%20MAX%20(%20'Calendar'%5BDate%5D%20)%0ARETURN%0A%20%20%20%20CALCULATE%20(%0A%20%20%20%20%20%20%20%20COUNTA%20(%20Table1%5BSuccess%5D%20)%2C%0A%20%20%20%20%20%20%20%20'Calendar'%5BDate%5D%20%26gt%3B%3D%20mindate%0A%20%20%20%20%20%20%20%20%20%20%20%20%26amp%3B%26amp%3B%20'Calendar'%5BDate%5D%20%26lt%3B%3D%20maxDate%0A%20%20%20%20)%0A%0A%0Aaccounts%20bought%3A%3DVAR%20mindate%20%3D%0A%20%20%20%20MIN%20(%20'Calendar'%5BDate%5D%20)%0AVAR%20maxDate%20%3D%0A%20%20%20%20MAX%20(%20'Calendar'%5BDate%5D%20)%0ARETURN%0A%20%20%20%20CALCULATE%20(%0A%20%20%20%20%20%20%20%20COUNTA%20(%20Table1%5BBought%5D%20)%2C%0A%20%20%20%20%20%20%20%20'Calendar'%5BDate%5D%20%26gt%3B%3D%20mindate%0A%20%20%20%20%20%20%20%20%20%20%20%20%26amp%3B%26amp%3B%20'Calendar'%5BDate%5D%20%26lt%3B%3D%20maxDate%0A%20%20%20%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-3107516%22%20slang%3D%22en-US%22%3ERe%3A%20Apply%20different%20date%20filters%20to%20specific%20column%20values%20in%20a%20pivot%20table%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-3107516%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F521%22%20target%3D%22_blank%22%3E%40Sergei%20Baklan%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20columns%20would%20be%20months%20on%20the%20pivot%20table%20and%20there%20would%20be%20different%20years%20as%20the%20row%20labels%3C%2FP%3E%3CP%3EAlso%2C%20your%20pivot%20table%20above%20is%20not%20accurate%20(there%20should%20be%200%20successful%20accounts%20in%20Jan%202021)%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Suppose I have the following pivot table from one data source

 

edb9afcecb8ba2370bef7b2e1146b13d.png

The source data is essentially a spreadsheet of accounts which indicates 3 items (3 columns)- date account was created, date account was successful, date account was bought.

There are 3 stages an account goes through: step 1 it gets created. Step 2, if the employee deems the account to be successful, they mark it as successful and mark the date it became successful. If there is more interest in the account, the account is bought and the company receives money for it - they mark the date it was bought.

If you look at the data, the # of created accounts > # of successful accounts > # of bought accounts.

However, a created account can be made in Jan 2021 for example, but can be successful in Feb 2021 and then bought in June 2021. An account cannot necessarily be created, be successful, and be bought all in the same month/year.

That's the problem I have with this pivot table - the values field I have is using the count of date created, count of date successful and the columns on my pivot table is grouped by quarters of Y2021. The rows of the pivot table are the different regions the account belongs to. The problem I have is I am grouping the dates based on the date created and data is being filtered strictly from that date created filter; I don't know how to create a "global" date filter that is not strictly based on the date created filter

So, in the February 2021 column for example, it is telling me I have 8 created accounts and 6 successful accounts, when there really should be 5 successful accounts. If you double click that cell which launches a table of that data, you'll see an account that was successful in August 2021, however, it was created in February 2021, so that is why it will say 6 successful accounts . That is an example of a discrepancy in my pivot table. If region3 has 10 created accounts in January 2021 for example, and in the same month/year, has 5 successful accounts (by looking at the source data) and one account becomes successful in July 2021, the pivot table should indicate that correctly as 10 created accounts in Jan 2021 and 5 successful accounts in January 2021.

11 Replies

@tytds 
not sure I understood entire logic. For such sample

image.png

- creating PivotTable add data to data model

- add Date (Calendar) table with PowerPivot or Power Query

- make relationship between it and main table on Date <=> Made

- add measures as

accounts made:=COUNTROWS ( Table1 )

accounts success:=VAR mindate =
    MIN ( 'Calendar'[Date] )
VAR maxDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        COUNTA ( Table1[Success] ),
        'Calendar'[Date] >= mindate
            && 'Calendar'[Date] <= maxDate
    )


accounts bought:=VAR mindate =
    MIN ( 'Calendar'[Date] )
VAR maxDate =
    MAX ( 'Calendar'[Date] )
RETURN
    CALCULATE (
        COUNTA ( Table1[Bought] ),
        'Calendar'[Date] >= mindate
            && 'Calendar'[Date] <= maxDate
    )

@Sergei Baklan 

The columns would be months on the pivot table and there would be different years as the row labels

Also, your pivot table above is not accurate (there should be 0 successful accounts in Jan 2021)

hmm i thought this would be an easier process. I don't want to play around with too much code but this date discrepancy is giving me a problem and I can't present my report accurately.

@tytds 

If to continue it's better if you generate small sample file to illustrate the logic manually adding desired result. That's 5-10 minutes job, your actual data is not required.

@tytds 
thank you, but that doesn't explain the logic. In sample file we have 12 accounts submitted in January. Each of them has Date Successful, thus all 12 of January accounts are successful.

 

Or you mean count successful accounts only if Date Successful is in January, doesn't matter when they were submitted?

 

Or some other logic?

When you setup a pivot table, there should be number of submitted accounts as a column, number of successful accounts in another column, and the hit ratio (simple formula successful/submitted). The number of submitted accounts in January should be 12. There should be a "sub column" for months. The number of successful accounts in the January column should be 4, meaning, those accounts turned successful in January. The number of successful accounts in March column (regardless when they were submitted) should be 2

@tytds 

With that you need to create separate Date (aka Calendar) table. That could be done by Power Query or directly in PowerPivot. Make relationships with main table and hide date fields in the latest.

image.png

Create measures

Submitted:=CALCULATE (
    COUNTROWS ( Range ),
    USERELATIONSHIP ( 'Calendar'[Date], Range[Date Submitted] )
)

and

Successed:=CALCULATE (
    COUNTROWS ( Range ),
    USERELATIONSHIP ( 'Calendar'[Date], Range[Date Successful] )
)

use them in PivotTable

image.png

Is there a tutorial on creating the relationships from the first picture? I'm not familiar with creating the measures either