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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Gaël
Regular Visitor

How to define the value of a cell to NULL in a "IF" sentence?

Hi!

 

I'm trying to define a cell to NULL in an IF sentence:

 

Column = IF(AND('public _view_powerbi__alm_x_periodo'[AFI]>='public _view_powerbi__alm_x_periodo'[PFI];'public _view_powerbi__alm_x_periodo'[AFI]<='public _view_powerbi__alm_x_periodo'[PFF]);'public _view_powerbi__alm_x_periodo'[id_alumno$];NULL)

 

The system replies : Operator or expression 'NULL' is not admited in this context.

 

If I set the value of cell to 0 (for exemple), a problem will appear when I will do a DISTINCTCOUNT for this column counting the 0 and the final information is wrong.

 

How can I do for or set cell to NULL or do not count the 0 value in a DISTINCTCOUNT?

 

I'm directly connected to the Data Base (Postgresql).

 

Thank you very much for your help.

 

 

 

Edited: I've created a new column where Vacio =  and I modified the original sentence to

 

column = IF(AND('public _view_powerbi__alm_x_periodo'[AFI]>='public _view_powerbi__alm_x_periodo'[PFI];'public _view_powerbi__alm_x_periodo'[AFI]<='public _view_powerbi__alm_x_periodo'[PFF]);'public _view_powerbi__alm_x_periodo'[id_alumno$];'public _view_powerbi__alm_x_periodo'[Vacio])

 

but the problem with DISTINCTCOUNT stills the same... It counts the empty cells...

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

calculate(distinctcount((your column name here) ) , (your column name here) <> 0)

 

I'm assuming the column has only numerical values. If not then replace the 0 with '' or "" 

 

 

 

View solution in original post

7 REPLIES 7
Mr_Niels
Regular Visitor

Hi Gaël,

 

what works well for me to count distinctvalues is to create a measure with this formula (not my find originally, but I don't know the source anymore):

 

Calculate(DistinctCount(tablename[columnname]);Filter(tablename;Not(isblank(tablename[columnname]))))

 

I'm quite new to Power BI, but I think you can assign a Null value by using just lowercase letters (null rather than Null or NULL)

 

cheers,

Niels

That only applies to the query editor. There are two languages in Power BI. In a query you can return null by typing null in lowercase. In a DAX formula use BLANK().





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




This is the only answer to the question that was asked and should be the accepted response. The others may have solved OP's issue, but they did not answer the question. 

 

IF ( x = 7 , 7 , BLANK() )

Thank you!!! DAX is really messing with me.
Short version of how I'm transposing my DW data with your input.

 

ex:

IF( 'value_label'="Federal Tax(s)", value('value_amount'), blank()

I know this is old, but I just tested to remove the comma and values for the "if false" portion of the formula.

 

So instead of typing ", blank() )", just clost the expression BEFORE the value if false with the close parentheses ")".

Anonymous
Not applicable

calculate(distinctcount((your column name here) ) , (your column name here) <> 0)

 

I'm assuming the column has only numerical values. If not then replace the 0 with '' or "" 

 

 

 

Thanks a lot danielhjorvar, it works perfectly

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

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! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.