Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Foolke
Helper I
Helper I

find penultimate (last -1) date in the table

All,
I have the following mesure to extract the last date from a table: 

INC last date = CALCULATE(sum(Tickets[INCIDENT]);LASTDATE(Tickets[TicketDate]))

I want to compare the value (number of tickets) of this date with the number of tickets of the penultimate date in the table.

  • Which measure can I use to find the penultimate date?
  • Which visual could I use for this? Iwant something like in screenshot (excel) but in Power BI.
    screenshotscreenshot

Thx

7 REPLIES 7
parry2k
Super User
Super User

@Foolke can you share sample data with expected output?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k 

Data:

TicketDateResponsible GroupINCIDENTSRQ
04/12/2019Westteam253100
25/11/2019Westteam239120

 

example output from excel

2019-12-09 06_21_10-Clipboard.png

 

Hi @Foolke ,

You can refer to the following steps if they meet for your requirements.

Steps:

1. Enter to query editor and do unpivoted columns on value fields incident SRQ.

Unpivot columns (Power Query) 

2. Create a matrix visual with attribute as row, ticketDate as column.

3. Write a measure formula to use current attribute and date to calculate the dynamic results and use on matrix value field.

Measure =
IF (
    ISFILTERED ( 'Sample'[TicketDate] ),
    CALCULATE ( SUM ( 'Sample'[Value] ), VALUES ( 'Sample'[Attribute] ) ),
    VAR _max =
        CALCULATE ( MAX ( 'Sample'[TicketDate] ), VALUES ( 'Sample'[Attribute] ) )
    VAR _previous =
        CALCULATE (
            MAX ( 'Sample'[TicketDate] ),
            FILTER ( ALLSELECTED ( 'Sample' ), [TicketDate] < _max ),
            VALUES ( 'Sample'[Attribute] )
        )
    RETURN
        CALCULATE (
            SUM ( 'Sample'[Value] ),
            FILTER ( ALLSELECTED ( 'Sample' ), [TicketDate] = _max ),
            VALUES ( 'Sample'[Attribute] )
        )
            - CALCULATE (
                SUM ( 'Sample'[Value] ),
                FILTER ( ALLSELECTED ( 'Sample' ), [TicketDate] = _previous ),
                VALUES ( 'Sample'[Attribute] )
            )
)

4. Modify subtotal -> column total to change display aggregate field name.

1.png

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thx @v-shex-msft , The unpivot table does a part of the job.

The only remaining challenge is to select the last 2 values from the dates.

Dates are updated every week. I am only interested in the last 2 dates. 

 

 

Hi @Foolke ,

Do you mean your table contains a lot of records but you only want to display the last two dates? If this is a case, you can add a visual level filter on date fields with 'TopN' mode to choose 'top' 2 dates.

5.png
Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Thx @v-shex-msft , we are getting there.

Now I have a last problem. 

How can I make sure that the 2 columns are subtracted instead of summing (column a - column b)? If I do this via agregation it doesn't work. See screenshot

 

 

2019-12-11 09_49_12-Clipboard.png

HI @Foolke,

I don't think you can achieve this via aggregation features. In my opinion, I'd like to suggest you create a new calculated column to store the result of 'column A'- 'Column B'.

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.