0

I'm displaying the record count of a DE Column,

%%[
VAR @rows, @row, @rowCount, @ID
SET @Lookup = "Yes"
SET @rows = LookupRows("Job","Lookup", @Lookup)
SET @rowCount = rowcount(@rows)

IF @rowCount > 0 THEN 
FOR @i =1 TO @rowcount DO
SET @row = row(@rows,@i) 
SET @MID = field(@row,"AccountID")

IF @MID == 123456 then  
SET @Greece = rowcount(lookuprows('Job','AccountID',@MID))  

ELSEIF @MID == 234567 then  
SET @Germany = rowcount(lookuprows('Job','AccountID',@MID))

ELSEIF @MID == 456789 then  
SET @India = rowcount(lookuprows('Job','AccountID',@MID))  
ENDIF  
NEXT @i  
]%%

Greece: %%=v(@Greece)=%%  <br> 
Germany: %%=v(@Germany)=%%  <br> 
India: %%=v(@India)=%%

%%[ ELSE ]%%  
%%[ ENDIF ]%%

But I'm not able to display '0' value , it is showing blank if there are no records.

Anyone please help me?

Thanks in advance Sai

0

If I am understanding, your issue is that if it doesn't have the selected MID in the Rowset, then since the Rowcount() is not run, it is not set to a value. The easiest way to handle this is to set them prior to your conditional declaraionts. Like so:

%%[
VAR @rows, @row, @rowCount, @ID
SET @Lookup = "Yes"
SET @rows = LookupRows("Job","Lookup", @Lookup)
SET @rowCount = rowcount(@rows)

SET @Greece = 0
SET @Germany = 0
SET @India = 0

IF @rowCount > 0 THEN 
FOR @i =1 TO @rowcount DO
SET @row = row(@rows,@i) 
SET @MID = field(@row,"AccountID")

IF @MID == 123456 then  
SET @Greece = rowcount(lookuprows('Job','AccountID',@MID))  

ELSEIF @MID == 234567 then  
SET @Germany = rowcount(lookuprows('Job','AccountID',@MID))

ELSEIF @MID == 456789 then  
SET @India = rowcount(lookuprows('Job','AccountID',@MID))  
ENDIF  
NEXT @i  
]%%

Greece: %%=v(@Greece)=%%  <br> 
Germany: %%=v(@Germany)=%%  <br> 
India: %%=v(@India)=%%

%%[ ENDIF ]%%

This will set a 'default' value that will fill in when called despite no rows matching in your conditional. Also, unless you have content to place inside of it, there is no need for the ELSE statement.

Output with only rows returned for Greece:

Greece: 3
Germany: 0
India: 0
| improve this answer | |
  • 1
    Thanks a lot , it worked – sai Jul 27 at 14:37
0

This could be made more dynamic, but without touching any existing code, wouldn't a simple "is empty check" for each country be enough?

VAR @rows, @row, @rowCount, @ID
SET @Lookup = "Yes"
SET @rows = LookupRows("Job","Lookup", @Lookup)
SET @rowCount = rowcount(@rows)

IF @rowCount > 0 THEN 
    FOR @i =1 TO @rowcount DO
    SET @row = row(@rows,@i) 
    SET @MID = field(@row,"AccountID")
    IF @MID == 123456 then  
        SET @Greece = rowcount(lookuprows('Job','AccountID',@MID))  
        IF empty(@Greece) THEN
            SET @Greece = 0
        ENDIF
    ELSEIF @MID == 234567 then  
        SET @Germany = rowcount(lookuprows('Job','AccountID',@MID))
        IF empty(@Germany) THEN
            SET @Germany = 0
        ENDIF
    ELSEIF @MID == 456789 then  
        SET @India = rowcount(lookuprows('Job','AccountID',@MID))  
        IF empty(@India) THEN
            SET @India = 0
        ENDIF
    ENDIF  
NEXT @i  
]%%

Greece: %%=v(@Greece)=%%  <br> 
Germany: %%=v(@Germany)=%%  <br> 
India: %%=v(@India)=%%

%%[ 
ELSE 
]%%  
%%[ 
ENDIF 
]%%
| improve this answer | |
  • Thanks a lot , but unfortunately it is showing the same result. Using set @germany = 0 worked fine. – sai Jul 27 at 14:34
  • Yes, correct. It is a number. I edited the answer. I got confused now, did this work in the end or are you still looking for an answer? – Jonas Lamberty Jul 27 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.