The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi PBI Experts.
Here is my question for you in dax ,
I have total sales for 4 months but data is loading for 2 months instead of 4 months.
In this case i need to create logic using Dax function. where data is not loaded for that month,then i need to get data for the previous month.
If Previous month data also not loaded then get data for the before last month.
Here are the screenshots for example.
will give kudos
Advance Thanks,
Thanks
Chaitanya
Solved! Go to Solution.
Hi @Chaitanya122 ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:
Measure =
VAR _selyear =
SELECTEDVALUE ( 'Date'[Year] )
VAR _selmonth =
SELECTEDVALUE ( 'Date'[Month] )
VAR _selym =
SELECTEDVALUE ( 'Date'[YearMonth] )
VAR _amount =
CALCULATE (
SUM ( 'Table'[Amount] ),
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = _selyear
&& FORMAT ( 'Table'[Date], "mmmm" ) = _selmonth
)
)
VAR _predate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALLSELECTED ( 'Table' ),
VALUE ( YEAR ( 'Table'[Date] ) & FORMAT ( 'Table'[Date], "mm" ) )
< VALUE ( _selym )
)
)
VAR _preamount =
CALCULATE (
SUM ( 'Table'[Amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[Date] ) = YEAR ( _predate )
&& MONTH ( 'Table'[Date] ) = MONTH ( _predate )
),
ALL ( 'Date' )
)
RETURN
IF ( ISBLANK ( _amount ), _preamount, _amount )
In addition, you can refer the following blog to get it.
Power BI DAX Getting the Value of Previous Non-NULL Row
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
How to upload PBI in Community
Best Regards
Hi @Chaitanya122 ,
I created a sample pbix file(see attachment) for you, please check whether that is what you want. You can create a measure as below:
Measure =
VAR _selyear =
SELECTEDVALUE ( 'Date'[Year] )
VAR _selmonth =
SELECTEDVALUE ( 'Date'[Month] )
VAR _selym =
SELECTEDVALUE ( 'Date'[YearMonth] )
VAR _amount =
CALCULATE (
SUM ( 'Table'[Amount] ),
FILTER (
'Table',
YEAR ( 'Table'[Date] ) = _selyear
&& FORMAT ( 'Table'[Date], "mmmm" ) = _selmonth
)
)
VAR _predate =
CALCULATE (
MAX ( 'Table'[Date] ),
FILTER (
ALLSELECTED ( 'Table' ),
VALUE ( YEAR ( 'Table'[Date] ) & FORMAT ( 'Table'[Date], "mm" ) )
< VALUE ( _selym )
)
)
VAR _preamount =
CALCULATE (
SUM ( 'Table'[Amount] ),
FILTER (
ALLSELECTED ( 'Table' ),
YEAR ( 'Table'[Date] ) = YEAR ( _predate )
&& MONTH ( 'Table'[Date] ) = MONTH ( _predate )
),
ALL ( 'Date' )
)
RETURN
IF ( ISBLANK ( _amount ), _preamount, _amount )
In addition, you can refer the following blog to get it.
Power BI DAX Getting the Value of Previous Non-NULL Row
If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
How to upload PBI in Community
Best Regards
This is a standard "penultimate" pattern. What have you tried and where are you stuck?
User | Count |
---|---|
5 | |
3 | |
3 | |
2 | |
1 |
User | Count |
---|---|
11 | |
7 | |
5 | |
5 | |
4 |