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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
IF
Post Prodigy
Post Prodigy

previous value

Hi,

I have to tables. Table "MonthYear" provides the months at the slicer. "Month" column is text. "Order" column is numeric. The other table is for calculation. I have a slicer for selection of month and I have two cards. If I select "06.2020" I want to get result in two cards one for "06.2020" and the other card should show data for "05.2020". The second card should always show order-1 data. For the first card, I get the result "DIVIDE(SUM(Actual[Days]), SUM(Actual[req]))". I don't how to get the result for second card. Also I want to keep the "month" with text format.

MonthYear

MonthOrder
06.20204
05.20203
04.20202
03.20201

 

Actual

Daysreqmonth
5406.2020
4206.2020
3206.2020
5206.2020
3305.2020
5205.2020
7505.2020
5505.2020

Thanks in advance!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @IF,

Yes, it is possible.
You can extract current date text value and use it to find out the index, then do the calculation to get the previous month index and use it as a condition to filter table records to find out the previous date text.

BTW, I also modify measure formula to replace allselcted with all function, you can try it if it works:

Previous result =
VAR _current =
    SELECTEDVALUE ( Actual[month], MAX ( Actual[month] ) )
VAR prev =
    FORMAT (
        DATE ( RIGHT ( _current, 4 ), LEFT ( _current, 2 ) - 1, 1 ),
        "mm.yyyy"
    )
RETURN
    CALCULATE (
        DIVIDE ( SUM ( Actual[Days] ), SUM ( Actual[req] ) ),
        FILTER ( ALL ( Actual ), [month] = prev )
    )

Regards,

Xiaoxin Sheng

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

HI @IF,

If you not want to convert your fields as date formula, you may need some conversion variable to do transform between these value and calculate the previous/next value and use it as filter conditions.

Measure formulas:

current result =
DIVIDE ( SUM ( Actual[Days] ), SUM ( Actual[req] ) )

Previous result =
VAR _current =
    SELECTEDVALUE ( Actual[month], LASTNONBLANK ( Actual[month], 1 ) )
VAR prev =
    FORMAT (
        DATE ( RIGHT ( _current, 4 ), LEFT ( _current, 2 ) - 1, 1 ),
        "mm.yyyy"
    )
RETURN
    CALCULATE (
        DIVIDE ( SUM ( Actual[Days] ), SUM ( Actual[req] ) ),
        FILTER ( ALLSELECTED ( Actual), [month] = prev )
    )

Regards,
Xiaoxin Sheng

Hi,

 

Thanks for the reply. I tried it didn't work. I want to highlight that the "month" column in both tables are in text format. I would like to use the " order" column in order to get previous month. Would it be possible?

 

Here is the image that I took:

1.jpg2.jpg

Anonymous
Not applicable

Hi @IF,

Yes, it is possible.
You can extract current date text value and use it to find out the index, then do the calculation to get the previous month index and use it as a condition to filter table records to find out the previous date text.

BTW, I also modify measure formula to replace allselcted with all function, you can try it if it works:

Previous result =
VAR _current =
    SELECTEDVALUE ( Actual[month], MAX ( Actual[month] ) )
VAR prev =
    FORMAT (
        DATE ( RIGHT ( _current, 4 ), LEFT ( _current, 2 ) - 1, 1 ),
        "mm.yyyy"
    )
RETURN
    CALCULATE (
        DIVIDE ( SUM ( Actual[Days] ), SUM ( Actual[req] ) ),
        FILTER ( ALL ( Actual ), [month] = prev )
    )

Regards,

Xiaoxin Sheng

Hi,

 

Thanks a lot! The measure works. You said that I can extract the current date text value and use it to find out index. For example; if a user selects "05.2020" the order (I mean index) for it is 3. How can I extract it?

 

On the other hand, previous month will be 3-1, which is 2. I want to show value for 2, which corresponds the previous month. How can I do it? You already mentioned but I didn't really understand it.

 

Bwy, I will accept the solution, but this way can be easier to use.

 

Best regards,

IF

ryan_mayu
Super User
Super User

@IF 

 

I suggest you create a datetime table and create relationship between actual table and datetime table.

 

Since you need to connect two table by using date column, at first you change the month column to date type.

 

date = date(right(actual[month],4),left(actual[month],1),1)

1.PNG

 

Then create two measures

this month = sum(actual[Days])/sum(actual[req])

last month = CALCULATE(sum(actual[Days]),DATEADD('datetime'[Date],-1,month))/ CALCULATE(sum(actual[req]),DATEADD('datetime'[Date],-1,month))

 

Since you want to keep the filter as text, you need to switch the date column to text value in the datetime table

monthtext = month('datetime'[Date])&"."&year('datetime'[Date])

3.PNG

 

 

 

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hi!

Thanks for the answer. Both tables are link to eachother through month column. The month colum in both tables are text. I don't want to change it into date format. As you said, maybe it is a better solution. However, I made some progress with my report. it will effect the rest. So, is there any possibility to have a measure while keeping the "month" column in both table in text format?

All the best,

IF

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.