Last None Blank DAX Measure - dax

I have the results as:
but need the results to appear as:
ie. where the last value with data will fill up the entire horizon for that year, each month defaulting to the last month with data.
Attempting to use the DAX as:
[Land Dev YTD]:= VAR LastNoneblankDate = CALCULATE(max('Date'[Date]),FILTER(Hyperion,[Land Dev] > 0)) return IF([Land Dev] = 0,CALCULATE([Land Dev],FILTER(ALL('Date'),'Date'[Date]=LastNoneblankDate)),[Land Dev])
Should in theory be sufficient, ie. supplant the result, where 0, to the value whereby the data is last present. However, the result is:
as it blows away all the other dates where there is not data.
How can I get this resolved?

Related

Power BI Measure returning Blank when it shouldn't

I am trying to create a measure that will return a value for the number of issued receipts in the year 2020:
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year] = 2020))
However, the measure keeps returning blank, even as a calculated column.
I've also tried
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year].Year = 2020))
But that is returning an error saying the syntax for "Year" is incorrect.
The Year column is of datatype Date and is linked to a dimDate table on the Date column.
I am trying to retrieve the value 440,000. What am I doing wrong?
Try this.
CALCULATE(SUM(Receipts[issued]), YEAR(Receipts[Year]) = 2020)

HOW TO REFERENCE A MEASURE IN A FILTER (DAX)

I have created a measure
Report_Day = MAX(DATE_LT[Date])-2
I want to create measures where they reference this measure so i can just change -2 to -1 and the rest of measures work depending on the reporting date.
when i use this measure:
Day_outlet_Txns = CALCULATE(
[outlet_Dep_Txns],
FILTER(ALL(DATE_LT),[Report_Day])
)
i get a value equal to tatal transactions in a table yet i want for transactions of that report day.
When i try something else
Day_outlet_Txns = CALCULATE(
[Issuer_Dep_Txns],
FILTER(ALL(DATE_LT), DATE_LT=[Report_Day])
)
i get an error: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.
enter image description here

How to insert previous month of data into database Nifi?

I have data in which i need to compare month of data if it is previous month then it should be insert otherwise not.
Example:
23.12.2016 12:02:23,Koji,24
22.01.2016 01:21:22,Mahi,24
Now i need to get first column of data (23.12.2016 12:02:23) and then get month (12) on it.
Compared that with before of current month like.,
If current month is 'JAN_2017',then get before of 'JAN_2017' it should be 'Dec_2016'
For First row,
compare this 'Dec_2016'[month before] with month of data 'Dec_2016' [23.12.2016].
It matched then insert into database.
EDIT 1:
i have already tried with your suggestions.
"UpdateAttribute to add a new attribute with the previous month value, and then RouteOnAttribute to determine if the flowfile should be inserted "
i have used below expression language in RouteOnAttribute,
${literal('Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec'):getDelimitedField(${csv.1:toDate('dd.MM.yyyy hh:mm:ss'):format('MM')}):equals(${literal('Dec,Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov'):getDelimitedField(${now():toDate(' Z MM dd HH:mm:ss.SSS yyyy'):format('MM'):toNumber()})})}
it could be failed in below data.,
23.12.2015,Andy,21
23.12.2017,Present,32
My data may contains some past years and future years
It matches with my expression it also inserted.
I need to check month with year in data.
How can i check it?
The easiest answer is to use the ExecuteScript processor with simple date logic (this will allow you to use the Groovy/Java date framework to correctly handle things like leap years, time zones, etc.).
If you really don't want to do that, you could probably use a regex and Expression Language in UpdateAttribute to add a new attribute with the previous month value, and then RouteOnAttribute to determine if the flowfile should be inserted into the database.
Here's a simple Groovy test demonstrating the logic. You'll need to add the code to process the session, flowfile, etc.
#Test
public void textScriptShouldFindPreviousMonth() throws Exception {
// Arrange
def input = ["23.12.2016 12:02:23,Koji,24", "22.01.2016 01:21:22,Mahi,24"]
def EXPECTED = ["NOV_2016", "DEC_2015"]
// Act
input.eachWithIndex { String data, int i ->
Calendar calendar = Date.parse("dd.MM.yyyy", data.tokenize(" ")[0]).toCalendar()
calendar.add(Calendar.MONTH, -1)
String result = calendar.format("MMM_yyyy").toUpperCase()
// Assert
assert result == EXPECTED[i]
}
}

Errors when grouping by list in Power Query

I have a set of unique items (Index) to each of which are associated various elements of another set of items (in this case, dates).
In real life, if a date is associated with an index, an item associated with that index appeared in a file generated on that date. For combination of dates that actually occurs, I want to know which accounts were present.
let
Source = Table.FromRecords({
[Idx = 0, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}],
[Idx = 1, Dates = {#date(2016,2,1), #date(2016,2,2), #date(2016,2,3)}],
[Idx = 2, Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]},
type table [Idx = number, Dates = {date}]),
// Group by
Grouped = Table.Group(Source, {"Dates"}, {{"Idx", each List.Combine({[Idx]}), type {number}}}),
// Clicking on the item in the top left corner generates this code:
Navigation = Grouped{[Dates={...}]}[Dates],
// Which returns this error: "Expression.Error: Value was not specified"
// My own code to reference the same value returns {0,2} as expected.
CorrectValue = Grouped{0}[Idx],
// If I re-make the table as below the above error does not occur.
ReMakeTable = Table.FromColumns(Table.ToColumns(Grouped), Table.ColumnNames(Grouped))
in ReMakeTable
It seems that I can use the results of this in my later work even without the Re-make (I just can't preview cells correctly), but I'd like to know if what's going on that causes the error and the odd code at the Navigation step, and why it disappears after the ReMakeTable step.
This happens because when you double click an item, the auto-generated code uses value filter instead of row index that you are using to get the single row from the table. And since you have a list as a value, it should be used instead of {...}. Probably UI isn't capable to work with lists in such a situation, and it inserts {...}, and this is indeed an incorrect value.
Thus, this line of code should look like:
Navigate = Grouped{[Dates = {#date(2016,1,1), #date(2016,1,2), #date(2016,1,3)}]}[Idx],
Then it will use value filter.
This is a bug in the UI. The index the UI calculates is incorrect: it should be 0 instead of [Dates={...}]. ... is a placeholder value, and it generates the "Value was not specified" exception if it is not replaced.

how to make sub total and grand total blank using DAX in tabular model?

12 Month Qty:=CALCULATE (
[Qty],
DATESINPERIOD (
Calendar[Date] ,
MAX(Calendar[Date]),
-12, Month
)
)
currently i have that formula for my measurement.
However i would like to make all sub totals and grad totals to be blank. Therefore i would need to put ISFILTERED function properly. i wrapped formula with if(ISFILTERED()) and it did not work well. So how can i implement ISFILTERED function correctly? or if I have to use different formula what formula should i use for this situation?
Based on your comments on the original question:
ISFILTERED() has to take a column as its argument, not a measure. ISFILTERED() will tell you if a filter has been applied (via a pivot table row, column, filter, or slicer) to a specific column in your model. Thus you can use it to suppress evaluation of a measure at certain levels of the hierarchy.
Say you have a measure that you want to display as a BLANK when at the subcategory level of a hierarchy that goes Category>SubCategory>Item:
IF(
ISFILTERED(<table>[SubCategory])
,BLANK()
,[Measure]
)
This would return a blank anywhere that [SubCategory] column has a filter applied.
Edit for comment:
Whichever level of the hierarchy you want to blank is the column to reference in ISFILTERED().
I'll typically use this pattern with a date hierarchy to display different levels of aggregation, and I tend to prefer HASONEVALUE() as my test. I'll apply a series of these tests in a SWITCH() function. SWITCH() is merely syntactic sugar for nested IF()s - you can look it up if you need a reference.
Thus:
MyConditionalMeasure:=
SWITCH( TRUE()
,HASONEVALUE(DimDate[Date]
// This means we're at the date level of the hierarchy
,[BaseMeasure] // The measure to evaluate at that first level
,HASONEVALUE(DimDate[Month])
// This is true for a month or a date only, but we've
// already captured the date possibility above
,[Month-appropriate Aggregation of BaseMeasure]
,HASONEVALUE(DimDate[Year])
// Again, true for a single date or a single month, but
// we've already covered those, so the year level is all
// that's left
,[Year-appropriate Aggregation of BaseMeasure]
,BLANK() // The last argument is taken as a final ELSE
// condition, capturing anything we didn't cover above,
// which would include the grand total - this will blank the
// grand total, or e.g. DimDate[Decade] since that is a
// coarser granularity than we covered with our tests above

Resources