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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AshDil
Helper V
Helper V

Want to show previous month data only after reaching to 7th of each Month

Hi,

 

I have two tables

Table-1:

DateSales
1-Jan-2310000
1-Feb-239000
1-Mar-2315000
1-Apr-2320000
1-May-231000

Table-2:

DateFuture Values
1-Jan-2312000
1-Feb-239000
1-Mar-2318000
1-Apr-2315000
1-May-2316000
1-Jun-2320000
1-Jul-2319000
1-Aug-2315000
1-Sep-2318000
1-Oct-2318000
1-Nov-2315000
1-Dec-2320000

 

In Stacked bar chart we need to show sales till closed month and future values for next 6 months.

The previous month is considered as closed only after reaching to 7th of current month

Which means

Today is 4th day of month (04-May-23), so April is not considered as closed - We need to show sales from Jan to Mar

Once the date has reached to 07-May-23, Apr is considered as closed - Then we need to show Sales from Jan to Apr.

 

Like wise the future values need to be shown for next 6 months

Which means

As today is 4th day of month (04-May-23) - The future values need to be shown from Apr to Sep

After reaching to 07-May-23 -  The future values need to be shown from May to Oct.

 

I have tried this by using following measures for Sales and Future values

 

Total Sales = SUM(Sales[Sales])
Sales till Previous Month = 
CALCULATE (
    [Total Sales],
    FILTER (
        'Calendar',
        'Calendar'[Date] <= EOMONTH ( TODAY (), -1 )
    )
)
Total Future Values = SUM('Future Values'[Future Values])
Future Values from Current Month = 
CALCULATE (
    [Total Future Values],
    FILTER (
        'Calendar',
        'Calendar'[Date] > EOMONTH ( TODAY (), -1 )
            && 'Calendar'[Date] <= EOMONTH ( TODAY (), 5 )
    )
)

 

The above measures didn't helped me.

 

Please help me to do this.

 

Thanks,

AshDil.

1 ACCEPTED SOLUTION
v-yueyunzh-msft
Community Support
Community Support

Hi , @AshDil 

Thanks for your sample data first!

According to your description, you want to show the sales and the future value in your logic .

Here are the steps you can refer to :

(1) I create a calendae date table like you and we do not need to create any relationship between two tables.

vyueyunzhmsft_2-1683519578883.png

(2)Then we can create a measure like this:

Measure = var _today = TODAY()
var _day = DAY(_today)
var _cur_month = MONTH(_today)
VAR _SALES_MONTH = IF(_day<=7,_cur_month-1,_cur_month)
VAR _FUTURE_MONTH= _SALES_MONTH+6
VAR year_MONTH =YEAR(MIN('Date'[Date]))*100+ MONTH( MIN('Date'[Date]))
VAR _DATE = MIN('Date'[Date])
VAR _SALES = CALCULATE( SUM('Table'[Sales]) , 'Table'[Date] = _DATE)
VAR _FUTURE = CALCULATE( SUM('Table2'[Future Values]) , 'Table2'[Date] = _DATE)

return
IF( year_MONTH <= YEAR(_today)*100 + _SALES_MONTH , _SALES, IF(year_MONTH > YEAR(_today)*100 + _SALES_MONTH && year_MONTH <= YEAR(_today)*100 + _FUTURE_MONTH,_FUTURE))

 

Then we can put this measure on the visual and we can meet your need:

vyueyunzhmsft_4-1683519632608.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

View solution in original post

2 REPLIES 2
v-yueyunzh-msft
Community Support
Community Support

Hi , @AshDil 

Thanks for your sample data first!

According to your description, you want to show the sales and the future value in your logic .

Here are the steps you can refer to :

(1) I create a calendae date table like you and we do not need to create any relationship between two tables.

vyueyunzhmsft_2-1683519578883.png

(2)Then we can create a measure like this:

Measure = var _today = TODAY()
var _day = DAY(_today)
var _cur_month = MONTH(_today)
VAR _SALES_MONTH = IF(_day<=7,_cur_month-1,_cur_month)
VAR _FUTURE_MONTH= _SALES_MONTH+6
VAR year_MONTH =YEAR(MIN('Date'[Date]))*100+ MONTH( MIN('Date'[Date]))
VAR _DATE = MIN('Date'[Date])
VAR _SALES = CALCULATE( SUM('Table'[Sales]) , 'Table'[Date] = _DATE)
VAR _FUTURE = CALCULATE( SUM('Table2'[Future Values]) , 'Table2'[Date] = _DATE)

return
IF( year_MONTH <= YEAR(_today)*100 + _SALES_MONTH , _SALES, IF(year_MONTH > YEAR(_today)*100 + _SALES_MONTH && year_MONTH <= YEAR(_today)*100 + _FUTURE_MONTH,_FUTURE))

 

Then we can put this measure on the visual and we can meet your need:

vyueyunzhmsft_4-1683519632608.png

 

 

Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

 

Best Regards,

Aniya Zhang

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

Hi @v-yueyunzh-msft ,

The measure worked for me. Thank you so much for your help.

Thanks,

AshDil

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.