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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
KVPro
Frequent Visitor

Last date value - lastnonblank doesn't working

Hello everyone

I have a big trouble with dax. I have some data with some blank rows for some months. If the value for month is blank i would like to get a value from previous time (month, week etc.)

 

My data is shown like this:

KVPro_0-1636447265164.png

My local max means max value for month, If I have data for Sept (9 month nr) 2020-09-12 and 2020-09-25, max shows me only 2020-09-25.

 

I don't know to do this for month, weeks etc. 

These are my attempts, I suppose, that I will be use only months as context, but I really want to use something else for dynamic choosing months, weeks, quarters etc.

 

Attempt 1:

Attempt1 =
If(
'FactTable'[Local Max] = BLANK(),
CALCULATE([Local Max],PREVIOUSMONTH('Calendar'[Date])),
'FactTable'[Local Max]
)
 
Result:
KVPro_1-1636447569791.png

If I have more than 1 month blanks, then I got empty value for example in 2020-11

 

Attemp2 -> I want to get something simillar to before attempt, but it is still incorrect.

Attempt2 =
IF(
[Attempt1] = BLANK(),
CALCULATE([Attempt1],PREVIOUSMONTH('Calendar'[Date])),
[Attempt1]
)
Result:
KVPro_2-1636447728847.png

Yes, I have data in correct form, but I am afraid, that If I will have more than 2 months of blank values, it will be incorrect.

 

So, I have tried use lastnonblank, but it is still incorrect :(:

Code:

Lastnonblank doesnt working =
If(
'FactTable'[Local Max] = BLANK(),
LASTNONBLANK('Calendar'[Date],[Local Max]),
[Local Max])
 
Result:
KVPro_3-1636447851533.png

 

Please help me, I have to do asap. 

6 REPLIES 6
VahidDM
Super User
Super User

Hi @KVPro 

 

As @lbendlin mentioned your post does not have enough information to go on;

But if I got your point correctly, try this code to add a new column to your table:

Column = 
VAR _A =
    CALCULATE (
        MAX ( 'Table'[Month nr] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Local max] <> BLANK ()
                && 'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Month nr] < EARLIER ( 'Table'[Month nr] )
        )
    )
VAR _B =
    CALCULATE (
        MAX ( 'Table'[Local max] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[Year] = EARLIER ( 'Table'[Year] )
                && 'Table'[Month nr] = _A
        )
    )
RETURN
    IF ( ISBLANK ( [Local max] ), _B, [Local max] )

 

Output:

VahidDM_0-1636597552583.png

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!


LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

KVPro
Frequent Visitor

It is incorrect in more than one products, these is my sample of Data

KVPro_1-1636729238303.png

 

I made it in real data by crossjoin products and SortID, I have a lot of products, so It is very very difficult to do

Hi @KVPro ,

 

It's easier to achieve in Power Query Editor.

1.Right click Product column, select group by. In operation, select All Rows.

vstephenmsft_0-1638944030626.png

vstephenmsft_1-1638944050187.png

vstephenmsft_4-1638944287804.png

 

 

 

2.Add a custom column.

= Table.FillDown([Count],{"Real Values"})

vstephenmsft_2-1638944244608.png

vstephenmsft_5-1638944300136.png

 

3.Remove the Count column and expand the Custom column.

vstephenmsft_6-1638944329871.png

vstephenmsft_7-1638944338680.png

 

4.Replace null with 0.

vstephenmsft_8-1638944416906.pngvstephenmsft_9-1638944428752.png

vstephenmsft_10-1638944433957.png

 

 

 

Best Regards,

Stephen Tao

 

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

 

 

 

 

 

Hi

Table has been created crossjoin some tables in DAX, so I cannot do it in PowerQuery and I have to use dax functions 😞

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. Paste the data into a table in your post or use one of the file services. Please show the expected outcome.

Sample of Data:

KVPro_0-1636729197255.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors