Forum Discussion

GSPBI's avatar
GSPBI
Frequent Visitor
4 years ago
Solved

Calculated Column - Show Last Week's Data in Current Week

Dear Microsoft PowerBI community,

 

I have been a long time user of this forum and I really appreciate all the users that raised their queries and the those that respond to them.


I have come across an issue that seems easy but I can't figure it out.


I have a table that looks like the below.

ABCD
IdPublication NumberActualPlanned
ExvfxB9PdcoRCuLKJalw371 
ExvfxB9PdcoRCuLKJalw36 1
fbHK1m9nAueKizAdKsWC371 
fbHK1m9nAueKizAdKsWC36 1
FuTeNOWeSSQ2tp4zhQ8V371 
FuTeNOWeSSQ2tp4zhQ8V36 1
G10bnm9UMTzoUtBeoyTl371 
G10bnm9UMTzoUtBeoyTl36 1


I want to create a calculated column F that moves last publication's planned figures (column D) in the current publication.



ABCDEF
IdPublication NumberActualPlannedNo. Activities AchievedNo. Activities Planned
ExvfxB9PdcoRCuLKJalw371 11
ExvfxB9PdcoRCuLKJalw36 1  
fbHK1m9nAueKizAdKsWC371 11
fbHK1m9nAueKizAdKsWC36 1  
FuTeNOWeSSQ2tp4zhQ8V371 11
FuTeNOWeSSQ2tp4zhQ8V36 1  
G10bnm9UMTzoUtBeoyTl371 11
G10bnm9UMTzoUtBeoyTl36 1  


What is the DAX calculated column that I need to produce? 

Any guidance would be appreciated.

 

Kind regards,

GSPBI

  • Hi GSPBI, this seems to work:

    No. Activities Planned = 
    VAR PublicationNumber = 'Table'[Publication Number]
    VAR PreviousPublicationNumber =
    CALCULATE(
    Max('Table'[Publication Number])
    , ALLEXCEPT('Table','Table'[Id])
    , ('Table'[Publication Number] < PublicationNumber)
    )
    RETURN
    CALCULATE(
    MAX('Table'[Planned])
    , ALLEXCEPT('Table', 'Table'[Id])
    , 'Table'[Publication Number] = PreviousPublicationNumber
    )

4 Replies

  • Hi GSPBI, this seems to work:

    No. Activities Planned = 
    VAR PublicationNumber = 'Table'[Publication Number]
    VAR PreviousPublicationNumber =
    CALCULATE(
    Max('Table'[Publication Number])
    , ALLEXCEPT('Table','Table'[Id])
    , ('Table'[Publication Number] < PublicationNumber)
    )
    RETURN
    CALCULATE(
    MAX('Table'[Planned])
    , ALLEXCEPT('Table', 'Table'[Id])
    , 'Table'[Publication Number] = PreviousPublicationNumber
    )
  • tamerj1's avatar
    tamerj1
    Community Champion

    Hi GSPBI 

    many options. 
    simplist is to to use LOOKUPVALUE and search for the same publication code but for publication number - 1

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi GSPBI ,

     

    If the Publication Number is continuous and  there is only one row for each Id and each Publication Number, please try:

    No. Activities Planned 1 = CALCULATE(MAX('Table'[Planned]),FILTER('Table',[Id]=EARLIER('Table'[Id]) && [Publication Number]=EARLIER('Table'[Publication Number])-1))

    Or

    No. Activities Planned 2 = LOOKUPVALUE('Table'[Planned],'Table'[Id],[Id],[Publication Number],[Publication Number]-1) 

    Output:

     

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