I have a 2 sheets
Sheet1 and Sheet2
I want to join the columns based on their #LP values. Which I am successful using the formula
=ArrayFormula(IFERROR(
{
Sheet1!A1:G,
vlookup(Sheet1!A1:A, {Sheet2!A1:A, Sheet2!B1:H}, {2,3,4}, false)
},"")
)
https://docs.google.com/spreadsheets/d/1I-7OYQx6eZ3a1AbxhBgOOpa632XNMh-gxKmGymnpxQ4/edit#gid=1245959930
I also want to skip the columns in result if the row names dynamically detrmining that wont begin with $ symbol.
The expected columns are shown in Green color as shown in the LP_QUERY1 sheet.
You can use MATCH and FILTER to get the columns you want.
=ArrayFormula(IFNA(
{
vlookup(
Sheet1!A1:A,
Sheet1!A1:G,
ArrayFormula(
MATCH(
FILTER(
Sheet1!1:1,
(LEFT(Sheet1!1:1,1)="$")+(Sheet1!1:1="#LP")
),
Sheet1!1:1,
0
)
)
,0
),
vlookup(
Sheet1!A1:A,
Sheet2!A1:H,
ArrayFormula(
MATCH(
FILTER(
Sheet2!1:1,
LEFT(Sheet2!1:1,1)="$"
),
Sheet2!1:1,
0
)
),
0
)
})
)
Related
I have a slicer from which I can select weeks that I want to show on a matrix. Currently, the matrix only shows the total column at the end of all columns basically summing up all the values.
But I want to show multiple total column (One after each month). Like after the End Of Weeks of one month a total column and so on.
You cannot simply create a Calculated column or Measure to solve this problem. Actually, you can use some logic with Calculated column, but there is a more efficient way. To achieve the goal, you have to create Calculated table based on your date column. You can use that logic to create any custom label for your visuals.
Before we start diving into deep DAX here, let's create a calendar table.
Calendar =
VAR _minSalesDate = CALCULATE( MIN( Sales[Date] ), ALL( Sales ) )
VAR _maxSalesDate = CALCULATE( MAX( Sales[Date] ), ALL( Sales ) )
RETURN
ADDCOLUMNS(
CALENDAR( _minSalesDate, _maxSalesDate ),
"Month", MONTH( [Date] ),
"MonthYear", MONTH( [Date] ) & "-" & YEAR( [Date] )
)
Now, when we have the table with our dates and additional fields, we can start creating a solution for this particular case.
Create a new calculated table as follows:
CustomCategories =
UNION(
SELECTCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[Sorter]
),
"Key", 'Calendar'[Date],
"Label", 'Calendar'[Date],
"LabelSorter", 'Calendar'[Sorter]
),
ADDCOLUMNS(
SELECTCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[MonthYear],
'Calendar'[Sorter]
),
"Key", 'Calendar'[Date],
"Label", 'Calendar'[MonthYear]
),
"LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALLEXCEPT( 'Calendar', 'Calendar'[MonthYear] ) ) + 0.5
),
SELECTCOLUMNS(
ADDCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[Sorter]
),
"LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALL( 'Calendar' ) ) + 1
),
"Key", 'Calendar'[Date],
"Label", "Total",
"LabelSorter", [LabelSorter]
)
)
Note that the last part of above DAX adding Total is optional.
Once the table has been created, go to the Data view, select CustomCategories table, select Label column and sort the column by LabelSorter (you will find an option on the ribbon). Then go back to your Model view and set a relationship between CustomCategories and your Fact table on Date column.
When you have done with all stuff above, switch back to the Report view. Remove the date column from your table visual and replace it with the newly created Label from CustomCategories table.
Now you should see the desired results.
Hope that helps!
Regards,
Arek
I've seen similar posts before, but none of the solutions worked for me as my formula is complex and includes filters.
I'm trying to create a new column in a table, concatenating all matches from a column in a different table.(e.g. Order table concatenating all product names associated with a given order)
Full formula: =
CONCATENATEX (
CALCULATETABLE (
RoW_SIC_table,
FILTER (
RoW_SIC_table,
RoW_SIC_table[Excel Company ID] = Row_main[Excel Company ID]
),
FILTER ( RoW_SIC_table, NOT ( ISBLANK ( RoW_SIC_table[Broad] ) ) )
),
RoW_SIC_table[Broad],
", "
)
I want CONCATENATEX to only concatenate unique values, and I haven't made it work with either DISTINCT or VALUES. Can you help me?
How about like this?
Full formula: =
CONCATENATEX (
CALCULATETABLE (
DISTINCT ( RoW_SIC_table[Broad] ),
FILTER (
RoW_SIC_table,
RoW_SIC_table[Excel Company ID] = Row_main[Excel Company ID]
)
),
RoW_SIC_table[Broad],
", "
)
I used as reference this:
e.g. Order table concatenating all product names associated with a
given order
So what came to my mind is the following model:
SIC Table
Main Table
"Data Model"
Result
ProductsListedByOrderIFBroadISNOTBLANK=
VAR COrderID=SIC[OrderID]
VAR PIDWLineage=
SELECTCOLUMNS(
CALCULATETABLE(SIC,
ALL(SIC), SIC[OrderID]=COrderID, NOT(ISBLANK(SIC[Broad]))),
"ProductID", SIC[ProductID], "ProductName", RELATED(Main[ProductName]))
RETURN
CONCATENATEX(PIDWLineage, [ProductName], ",")
I have two tables are Data and Report.
Data Table:
In Data table contain three columns are Item, status, and filter.
The item contains duplicated entry and the item column contains text and number or number only or text only.
The status column contains two different text/comments, "Okay" and "Not Okay"
The filter column contains two different filters which are A1 and A2.
The report table
In the Report table, I updated both comments/text as "Okay" or "Not Okay". I am looking for count against filter A1 and A2 according to the comments.
I would like to create a new calculated column in the report table in order to get the unique count according to the comments and filter based on the data table columns item and status.
DATA:
REPORT
Alexis Olson helped the following calculated column in order to get the unique count. I am trying to add one more filter in existing DAX calculated column but it's not working. Can you please advise?
1.Desired Result =
VAR Comment = REPORT[COMMENTS]
RETURN
CALCULATE (
DISTINCTCOUNT ( DATA[ITEM] ),
DATA[STATUS] = Comment
)
2.Desired Result =
COUNTROWS (
SUMMARIZE (
FILTER ( DATA, DATA[STATUS] = REPORT[COMMENTS] ),
DATA[ITEM]
)
)
3.Desired Result =
SUMX (
DISTINCT ( DATA[ITEM] ),
IF ( CALCULATE ( SELECTEDVALUE ( DATA[STATUS] ) ) = REPORT[COMMENTS], 1, 0 )
)
I think you can just add a filter to CALCULATE:
Filter by A1 Result =
VAR Comment = REPORT[COMMENTS]
RETURN
CALCULATE (
DISTINCTCOUNT ( DATA[ITEM] ),
DATA[STATUS] = Comment,
DATA[FILTER] = "A1"
)
For the second method,
Filter by A1 Result =
COUNTROWS (
SUMMARIZE (
FILTER ( DATA, DATA[STATUS] = REPORT[COMMENTS] && REPORT[FILTER] = "A1" ),
DATA[ITEM]
)
)
I do not recommend using the third one but it would be like this
Filter by A1 Result =
SUMX (
DISTINCT ( DATA[ITEM] ),
IF (
CALCULATE ( SELECTEDVALUE ( DATA[STATUS] ) ) = REPORT[COMMENTS]
&& CALCULATE ( SELECTEDVALUE ( DATA[FILTER] ) ) = "A1",
1,
0
)
)
I have a table like below in power BI with two columns Category and subcategory. I m trying to get the count of subcategory="S2" for each category into a calculated column (like in S2_count).
Category Subcategory S2_count
A S1 1
A S2 1
A S1 1
B S1 2
B S3 2
B S2 2
B S2 2
C S2 2
C S3 2
C S2 2
Is there a way using the DAX to get this ? I tried the below formula but no clue how to apply both filter and group by
s2_count =
CALCULATE(
COUNT(Test01[subcategory]),
GROUPBY(Test01,Test01[subcategory]))
Thy this:
s2_count =
COUNTROWS (
FILTER (
'Test01',
'Test01'[Category] = EARLIER ( 'Test01'[Category] )
&& 'Test01'[Subcategory] = "S2"
)
)
The EARLIER Function will return 'Test01'[Category] in its previous filtercontext, which is the rowcontext.
You can also do this using CALCULATE.
s2_count =
CALCULATE( COUNTROWS( Test01 ),
Test01[Subcategory] = "S2",
ALLEXCEPT( Test01, Test01[Category] )
)
The ALLEXCEPT function removes any of the row context except for the Category.
Note: If there are no other columns in your table, you don't need the ALLEXCEPT argument and you can just use this instead:
s2_count = CALCULATE( COUNTROWS( Test01 ), Test01[Subcategory] = "S2" )
If you do have other columns though, they are passed from row context to filter context along with the Category and you won't get the right result.
Presently my data returns:
What I need it to do is if the current month has 0's, it will default to the last months value with data:
I know this can be done with nested IF statements, but is there a better way?
UPDATED WITH #TPD SUGGESTION
The results from #TPD suggestion yield:
With measure defined as:
IF([Land Dev Alloc] = 0, CALCULATE([Land Dev Alloc],TOPN(1, CALCULATETABLE(Hyperion,FILTER(ALL(Hyperion), [Land Dev Alloc]>0)),Hyperion[DimDateID],DESC)),[Land Dev Alloc])
Where Hyperion is the main fact table that measure Land Dev Alloc pulls from
I'm not sure if this is the best way but I've recently solved a similar problem like this, assuming you have a Date table and a Value table joined with a relationship:
CurrentOrLastValue:=
CALCULATE (
-- EXTRACT VALUE FROM ROW
FIRSTNONBLANK( 'value'[value], 1 ),
-- FIRST ROW FROM YOUR 'VALUES' TABLE REDUCED TO THOSE BEFORE THE CURRENT CELL DATE
-- ORDERED BY DATE DESC
TOPN (
1,
CALCULATETABLE (
'value',
FILTER
(
ALL( 'date'[date] ),
'date'[date] <= MAX( 'date'[date] )
)
),
'value'[date],
DESC
)
)
Data tables and Pivot Table
Measure
Relationships
UPDATE TO SHOW MEASURE RESULT NOT RAW VALUE
Add a new core measure (doubling values to show a difference):
TotalValue:=SUM('value'[value]) * 2
Add a new measure to show desired output:
CurrentOrLastValueMeasure:=CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'date'[date] ),
'date'[date] <= MAX( 'date'[date] )
)
),
'value'[date],
DESC
)
)
New measure in pivot table:
UPDATE TO SHOW LAST NON-ZERO VALUE WHEN MEASURE RETURNS ZERO
LastNonZeroMeasure:=
IF( [TotalValue] = 0,
CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'value' ),
[TotalValue] > 0
)
),
'value'[date],
DESC
)
),
[TotalValue]
)
TotalValue not being doubled anymore. Two data points for 4th Jan to show the measure's aggregation working.
UPDATE TO IGNORE DATES AHEAD OF CELL DATE
Try filtering the dates also...
LastNonZeroMeasure:=IF( [TotalValue] = 0,
CALCULATE (
[TotalValue],
TOPN(
1,
CALCULATETABLE(
'value',
FILTER(
ALL( 'value' ),
[TotalValue] > 0
),
FILTER(
ALL( 'date' ),
'date'[date] < max( 'date'[date] )
)
),
'value'[date],
DESC
)
),
[TotalValue]
)
Ended up being far more simple than originally thought:
MeasureOne BALANCE YTD:= VAR LastNoneblankDate = CALCULATE(max('Date'[DimDateID]),FILTER(ALL('Date'),'Date'[Fiscal_Year] = MAX('Date'[Fiscal_Year])),FILTER(ALL(FactTable),[MeasureOne] > 0)) return IF([MeasureOne]=0, CALCULATE([MeasureOne],FILTER(ALL('Date'),'Date'[DimDateID] = LastNoneblankDate)), [MeasureOne BASE])
Where MeasureOne Base:
MeasureOne BASE:= VAR LastNoneblankDate = CALCULATE(max('Date'[Date]),FILTER(ALL(FactTable),[MeasureOne] > 0)) return IF(HASONEVALUE('Date'[Date]),[MeasureOne], CALCULATE([MeasureOne],FILTER(ALL('Date'),'Date'[Date] = LastNoneblankDate)))
the main issue was setting ALL(FactTable) instead of jut FactTable and handling the cases with