cancel
Showing results for
Did you mean:

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Helper V

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

Hi,

I have two tables

Table-1:

 Date Sales 1-Jan-23 10000 1-Feb-23 9000 1-Mar-23 15000 1-Apr-23 20000 1-May-23 1000

Table-2:

 Date Future Values 1-Jan-23 12000 1-Feb-23 9000 1-Mar-23 18000 1-Apr-23 15000 1-May-23 16000 1-Jun-23 20000 1-Jul-23 19000 1-Aug-23 15000 1-Sep-23 18000 1-Oct-23 18000 1-Nov-23 15000 1-Dec-23 20000

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.

Thanks,

AshDil.

1 ACCEPTED SOLUTION
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.

(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:

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

2 REPLIES 2
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.

(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:

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

Helper V

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

Thanks,

AshDil